参照CSS3景深、三维变换属性及旋转三维立方体的实现
.stage1 {
width: 200px;
height: 200px;
border: 1px solid black;
margin: 100px auto;
perspective: 500px;
}
.stage1 .demo {
width: 200px;
height: 200px;
background-color: orangered;
transform: rotateX(45deg);
}
ul {
padding: 0;
margin: 0;
list-style-type: none;
}
.stage {
position: relative;
width: 800px;
height: 800px;
margin: 100px auto;
perspective: 800px;
}
@keyframes move {
0% {
transform: rotateX(0deg);
}
25% {
transform: rotateX(180deg);
}
50% {
transform: rotateX(360deg) rotateY(0deg);
}
75% {
transform: rotateX(360deg) rotateY(180deg);
}
100% {
transform: rotateX(360deg) rotateY(360deg);
}
}
.stage .three-d-box {
width: 200px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
margin: -100px 0 0 -100px;
transform-style: preserve-3d;
animation: move 3s linear infinite;
}
.stage .three-d-box>li {
position: absolute;
width: 200px;
height: 200px;
left: 0;
top: 0;
font-size: 50px;
line-height: 200px;
text-align: center;
opacity: 0.5;
}
.stage .three-d-box>li:nth-child(1) {
background-color: red;
transform: translateZ(-100px);
}
.stage .three-d-box>li:nth-child(2) {
background-color: yellow;
transform: translateZ(100px);
}
.stage .three-d-box>li:nth-child(3) {
background-color: blue;
transform: rotateX(90deg) translateZ(100px);
}
.stage .three-d-box>li:nth-child(4) {
background-color: green;
transform: rotateX(-90deg) translateZ(100px);
}
.stage .three-d-box>li:nth-child(5) {
background-color: black;
transform: rotateY(90deg) translateZ(100px);
}
.stage .three-d-box>li:nth-child(6) {
background-color: purple;
transform: rotateY(-90deg) translateZ(100px);
}
<div class="stage1">
<div class="demo">1</div>
</div>
<div class="stage">
<ul class="three-d-box">
<li>红</li>
<li>黄</li>
<li>蓝</li>
<li>绿</li>
<li>黑</li>
<li>紫</li>
</ul>
</div>