html部分
<div class="box">
<div class="side front"></div>
<div class="side back"></div>
<div class="side left"></div>
<div class="side right"></div>
<div class="side top">
<div class="tl"></div>
<div class="tr"></div>
</div>
<div class="side bottom"></div>
</div>
css部分
*{
margin:0;
padding:0;
box-sizing: border-box;
}
body{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: rgb(5, 243, 243);
}
.box{
display: flex;
justify-content: center;
align-items: center;
position: relative;
transform-style:preserve-3d;
perspective: 1000px;
transform: rotateX(-20deg);
}
.side{
position: absolute;
width: 200px;
height: 200px;
background-color: rgb(226, 205, 15);
border: 1px solid #fff;
}
.front {
transform:translateZ(100px)
}
.back{
transform: translateZ(-100px) rotateY(180deg);
}
.left{
transform: translateX(-100px) rotateY(-90deg);
}
.right{
transform: translateX(100px) rotateY(90deg);
}
.top{
transform: translateY(-100px) rotateX(90deg);
background-color: transparent;
transform-style:preserve-3d;
}
.top div{
background-color: rgb(226, 205, 15);
position: absolute;
top: 0;
width: 50%;
height: 100%;
border:1px solid #fff;
}
.top .tl {
left: 0;
transform-origin: left;
}
.top .tr{
right: 0;
transform-origin: right;
}
.bottom{
transform: translateY(100px) rotateX(-90deg);
box-shadow: 5px -5px 15px rgb(0,0,0,0.4);
}
.box:hover .top .tl {
transform: rotateY(-135deg);
}
.box:hover .top .tr {
transform: rotateY(135deg);
}