<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
perspective: 2000px;
}
.box{
position: relative;
width: 300px;
height: 300px;
/* border: 2px solid red; */
margin: 200px auto;
transform-style: preserve-3d;
/* transform: rotateX(-20deg) rotateY(-20deg); */
animation: rotate 5s linear infinite;
}
.box div{
position: absolute;
left: 0;top: 0;
width: 300px;
height: 300px;
border: 2px solid black;
text-align: center;
line-height: 300px;
font-size: 50px;
transition:transform 1s;
}
.top{
transform: rotateX(90deg) translateZ(150px);
}
.bottom{
transform: rotateX(-90deg) translateZ(150px);
}
.left{
transform: rotateY(-90deg) translateZ(150px);
}
.right{
transform: rotateY(90deg) translateZ(150px);
}
.front{
transform: translateZ(150px);
}
.back{
transform:rotateY(180deg) translateZ(150px);
}
.box:hover .top{
transform:rotateX(90deg) translateZ(300px);
}
.box:hover .bottom{
transform:rotateX(-90deg) translateZ(300px);
}
.box:hover .left{
transform:rotateY(-90deg) translateZ(300px);
}
.box:hover .right{
transform:rotateY(90deg) translateZ(300px);
}
.box:hover .front{
transform:translateZ(300px);
}
.box:hover .back{
transform:rotateY(180deg) translateZ(300px);
}
@keyframes rotate {
0%{
transform: rotateY(0deg) rotateZ(0deg);
}
100%{
transform: rotateY(360deg) rotateZ(360deg);
}
}
</style>
</head>
<body>
<div class="box">
<div class="top">top</div>
<div class="bottom">bottom</div>
<div class="left">left</div>
<div class="right">right</div>
<div class="front">front</div>
<div class="back">back</div>
</div>
</body>
</html>