HTML+CSS 实现一个立方体
程序员文章站
2022-07-12 23:33:04
...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>立方体</title>
</head>
<style>
*{
padding: 0;margin: 0;
}
#cube{
width: 300px;height: 300px;
font-size: 80px; text-align: center;line-height: 300px;
transition: 2s;
transform: rotateY(-30deg) rotateX(-35deg);
transform-style: preserve-3d;
margin: 300px auto;
}
#cube:hover{
transform: rotateY(30deg) rotateX(35deg);
}
#cube > div{
width: 300px;height: 300px;position: absolute ;left: 0;top: 0;
transition: 2s;opacity: 0.5;
border: 1px dashed black;
}
#cube .flat1{
background-color:red; transform: translateY(-150px) rotateX(90deg);
}
#cube .flat2{
background-color:orange;transform: translateY(150px) rotateX(90deg);
}
#cube .flat3{
background-color:yellow;transform: translateX(-150px) rotateY(90deg);
}
#cube .flat4{
background-color:green;transform: translateX(150px) rotateY(90deg);
}
#cube .flat5{
background-color:lightgreen;transform: translateZ(150px) ;
}
#cube .flat6{
background-color:blue;transform: translateZ(-150px);
}
</style>
<body>
<div id="cube">
<div class="flat1">上</div>
<div class="flat2">下</div>
<div class="flat3">左</div>
<div class="flat4">右</div>
<div class="flat5">前</div>
<div class="flat6">后</div>
</div>
</body>
</html>