正方体
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
body{
overflow: hidden;
}
.box {
width: 300px;
height: 300px;
position: relative;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: 200px auto;
transform-style: preserve-3d;
/* -webkit-perspective: 250; */
text-align: center;
animation:move 7s linear infinite;
}
.box div {
width: 100%;
height: 100%;
position: absolute;
font: 50px/300px "微软雅黑";
transition: all .8s;
background-size: 100% 100%;
opacity: 0.7;
text-align: center;
}
@keyframes move{
from {transform:rotateX(0deg) rotateY(0deg);}
to {transform:rotateX(360deg) rotateY(360deg)}
}
.box div:nth-child(1) {
background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
transform: translateZ(150px);
box-shadow: 0 0 10px deepskyblue;
}
.box div:nth-child(2) {
background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
transform: rotateY(90deg) translateZ(150px);
box-shadow: 0 0 10px deepskyblue;
}
.box div:nth-child(3){
background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
transform: rotateY(180deg) translateZ(150px);
box-shadow: 0 0 10px deepskyblue;
}
.box div:nth-child(4) {
background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
transform: rotateY(270deg) translateZ(150px);
box-shadow: 0 0 10px deepskyblue;
}
.box div:nth-child(5) {
background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
transform: rotateX(90deg) translateZ(150px);
box-shadow: 0 0 10px deepskyblue;
}
.box div:nth-child(6) {
background: linear-gradient(#00FFFF,rgba(255,255,255,0.5));
transform: rotateX(270deg) translateZ(150px);
box-shadow: 0 0 10px deepskyblue;
}
.box:hover div:nth-child(1){
transform: translateZ(300px);
}
.box:hover div:nth-child(2){
transform:rotateY(90deg) translateZ(300px);
}
.box:hover div:nth-child(3){
transform:rotateY(180deg) translateZ(300px);
}
.box:hover div:nth-child(4){
transform:rotateY(270deg) translateZ(300px);
}
.box:hover div:nth-child(5){
transform:rotateX(90deg) translateZ(300px);
}
.box:hover div:nth-child(6){
transform:rotateX(270deg) translateZ(300px);
}
</style>
</head>
<body>
<div class="box">
<div>正前面</div>
<div>右面</div>
<div>正后面</div>
<div>左面</div>
<div>上面</div>
<div>下面</div>
</div>
</body>
</html>
双层的立方体
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D炫酷相册</title>
<style>
* {
margin: 0;
padding: 0;
}
:root,
body {
height: 100%;
width: 100%;
background-color: black;
}
/* 最外层容器样式 */
.container {
width: 200px;
height: 200px;
position: absolute;
perspective: 2000px;
/* 调整视距 */
top: calc(50% - 100px);
left: calc(50% - 100px);
/* 垂直水平居中 */
}
/*立方体容器样式*/
.cube {
width: 200px;
height: 200px;
transform-style: preserve-3d;
transform: rotateX(-30deg) rotateY(-80deg);
animation: roddy 10s linear infinite;
/*设置动画匀速重复*/
}
@keyframes roddy {
0% {
transform: rotateX(0deg) rotateY(0deg);
}
100% {
transform: rotateX(360deg) rotateY(360deg);
}
}
.cube div {
position: absolute;
width: 200px;
height: 200px;
opacity: 0.8;
/* 设置透明度 */
transition: all 0.4s;
/* 过渡动画 */
}
/* 外面照片大小设置 */
.out_pic {
width: 200px;
height: 200px;
}
.cube .out_front {
transform: rotateY(0deg) translateZ(100px);
}
.cube .out_back {
transform: rotateY(180deg) translateZ(100px);
}
.cube .out_left {
transform: rotateY(90deg) translateZ(100px);
}
.cube .out_right {
transform: rotateY(-90deg) translateZ(100px);
}
.cube .out_top {
transform: rotateX(90deg) translateZ(100px);
}
.cube .out_bottom {
transform: rotateX(-90deg) translateZ(100px);
}
.cube #small {
position: absolute;
width: 100px;
height: 100px;
top: 50px;
left: 50px;
}
/* 里面照片大小设置 */
.in_pic {
width: 100px;
height: 100px;
}
.cube .in_front {
transform: rotateY(0deg) translateZ(50px);
}
.cube .in_back {
transform: rotateY(180deg) translateZ(50px);
}
.cube .in_left {
transform: rotateY(90deg) translateZ(50px);
}
.cube .in_right {
transform: rotateY(-90deg) translateZ(50px);
}
.cube .in_top {
transform: rotateX(90deg) translateZ(50px);
}
.cube .in_bottom {
transform: rotateX(-90deg) translateZ(50px);
}
/*鼠标移入后样式*/
.cube:hover .out_front {
transform: rotateY(0deg) translateZ(200px);
}
.cube:hover .out_back {
transform: rotateY(180deg) translateZ(200px);
}
.cube:hover .out_left {
transform: rotateY(90deg) translateZ(200px);
}
.cube:hover .out_right {
transform: rotateY(-90deg) translateZ(200px);
}
.cube:hover .out_top {
transform: rotateX(90deg) translateZ(200px);
}
.cube:hover .out_bottom {
transform: rotateX(-90deg) translateZ(200px);
}
</style>
</head>
<body>
<div class="container">
<div class="cube">
<!-- 外面立方体开始 -->
<div class="out_front">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="out_pic" />
</div>
<div class="out_back">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="out_pic" />
</div>
<div class="out_left">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="out_pic" />
</div>
<div class="out_right">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="out_pic" />
</div>
<div class="out_top">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="out_pic" />
</div>
<div class="out_bottom">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="out_pic" />
</div>
<!-- 外面立方体结束 -->
<!-- 里面立方体开始 -->
<div class="in_front" id="small">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="in_pic" />
</div>
<div class="in_back" id="small">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="in_pic" />
</div>
<div class="in_left" id="small">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="in_pic" />
</div>
<div class="in_right" id="small">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="in_pic" />
</div>
<div class="in_top" id="small">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="in_pic" />
</div>
<div class="in_bottom" id="small">
<img src="https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3566088443,3713209594&fm=26&gp=0.jpg"
class="in_pic" />
</div>
<!-- 里面立方体结束 -->
</div>
</div>
</body>
</html>