CSS实现动画魔方
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>正方体</title>
<style>
*{
margin: 0;
padding: 0;
}
.box{
margin: 200px 400px;
width: 200px;
height: 200px;
position: absolute;
background-color: #000;
transform: perspective(800px) rotateX(30deg) rotateY(-45deg);
transform-style: preserve-3d;
transition: all 3s linear;
animation: move 3s linear infinite;
}
@keyframes move {
from{
transform: rotateX(0) rotateZ(0) rotateY(0);
}
to{
transform: rotateZ(60deg) rotateY(45deg) rotateZ(30deg);
}
}
.box:hover{
}
.box>div{
width: 200px;
height: 200px;
position: absolute;
left: 0;
top: 0;
}
.front{
transform: perspective(800px) translateZ(100px);
background-color: #ffa5e6;
}
.back{
transform: perspective(800px) translateZ(-100px);
background-color: #b4ff2f;
}
.left{
transform: perspective(800px) translateX(100px) rotateY(90deg);
background-color: #65ffcf;
}
.right{
transform: perspective(800px) translateX(-100px) rotateY(90deg) ;
background-color: #ffdc59;
}
.top{
transform: perspective(800px) translateY(-100px) rotateX(90deg);
background-color: #cfff87;
}
.bottom{
transform: perspective(800px) translateY(100px) rotateX(90deg);
background-color: #ff645f;
}
</style>
</head>
<body>
<div class="box">
<div class="front"></div>
<div class="back"></div>
<div class="left"></div>
<div class="right"></div>
<div class="top"></div>
<div class="bottom"></div>
</div>
</body>
</html>