<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>旋转立方体</title>
<style>
*{
margin:0;
padding:0;
}
body{
background: #222;
}
div.wrap{
width:200px;
perspective: 1000px;
position: absolute;
top:50%;
left:50%;
transform:translateX(-50%) translateY(-50%);
}
.cube{
width:200px;
height: 200px;
position: relative;
transform-style:preserve-3d;
transform: rotateX(-50deg) rotateY(-50deg) rotateZ(0deg);
animation: move 20s infinite linear;
}
.cube>div{
width:100%;
height:100%;
background:black;
position: absolute;
box-shadow:0 0 10px currentColor;
font-size: 50px;
text-align: center;
line-height: 200px;
}
.cube:hover>div{
background: currentColor;
box-shadow: 0 0 30px currentColor;
}
.cube .out-front{
transform: translateZ(100px);
color:deeppink;
}
.cube .out-back{
transform: translateZ(-100px) rotateY(-180deg);
color:seagreen;
}
.cube .out-left{
transform: translateX(-100px) rotateY(-90deg);
color:skyblue;
}
.cube .out-right{
transform: translateX(100px) rotateY(90deg);
color:lightcoral;
}
.cube .out-top{
transform: translateY(-100px) rotateX(90deg);
color:lightslategrey;
}
.cube .out-bottom{
transform: translateY(100px) rotateX(-90deg);
color:gold;
}
@keyframes move{
0%{
transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
}
100%{
transform: rotateX(360deg) rotateY(720deg) rotateZ(720deg);
}
/*from 和 to 也可以*/
}
</style>
</head>
<body>
<div class="wrap">
<div class="cube">
<div class="out-front">生</div>
<div class="out-back">*</div>
<div class="out-left">*</div>
<div class="out-right">快</div>
<div class="out-top">乐</div>
<div class="out-bottom">日</div>
</div>
</div>
</body>
</html>
效果很好,很漂亮!