用css和html写的正方体,六面体的旋转和分离
作者:互联网
代码如下
<!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: 1000px;
}
.box{
position: relative;
width: 300px;
height: 300px;
/* border: solid 2px black; */
margin: 200px auto;
transform: rotateY(30deg) rotateZ(10deg);
transform-style: preserve-3d;
transition: transform 4s linear;
animation: bianx 4s linear infinite;
}
.box div{
position: absolute;
top: 0px;
left: 0px;
width: 300px;
height: 300px;
border: solid 2px rgb(255, 115, 0);
background-color: chocolate;
font-size: 20px;
text-align: center;
transition: transform 0.5s linear;
line-height: 300px;
}
.shang{
transform: rotateX(90deg) translateZ(150px);
}
.xia{
transform: rotateX(-90deg) translateZ(150px);
}
.zuo{
transform: rotateY(-90deg) translateZ(150px);
}
.you{
transform: rotateY(90deg) translateZ(150px);
}
.qian{
transform:translateZ(150px);
}
.hou{
transform: /* rotateY(-180deg) */ translateZ(-150px);
}
.box:hover .shang{
transform: rotateX(90deg) translateZ(200px);
}
.box:hover .xia{
transform: rotateX(-90deg) translateZ(200px);
}
.box:hover .zuo{
transform: rotateY(-90deg) translateZ(200px);
}
.box:hover .you{
transform: rotateY(90deg) translateZ(200px);
}
.box:hover .qian{
transform:translateZ(200px);
}
.box:hover .hou{
transform: /* rotateY(-180deg) */ translateZ(-200px);
}
@keyframes bianx{
0%{
transform: rotate3d(-1,-1,-1,180deg);
}
100%{
transform: rotate3d(1,1,1,180deg);
}
}
</style>
</head>
<body>
<div class="box">
<div class="shang">上</div>
<div class="xia">下</div>
<div class="zuo">左</div>
<div class="you">右</div>
<div class="qian">前</div>
<div class="hou">后</div>
</div>
</body>
</html>
标签:正方体,box,translateZ,90deg,transform,rotateY,html,200px,六面体 来源: https://blog.csdn.net/weixin_52583582/article/details/110502373