使用旋转制作正方体
相关代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MTB</title>
<style>
* {
padding: 0;
margin: 0;
}
.box {
width: 200px;
height: 200px;
margin: 100px auto;
perspective: 300px;
position: relative;
}
.box p {
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 200px;
}
.box p:nth-child(1) {
background-color: rgba(243, 195, 118, 0.356);
/* 前面 */
transform: translateZ(100px);
}
.box p:nth-child(2) {
background-color: rgba(214, 247, 70, 0.356);
/* 顶部 */
transform: rotateX(90deg) translateZ(100px);
}
.box p:nth-child(3) {
background-color: rgba(163, 248, 93, 0.479);
/* 背面 */
transform: rotateX(180deg) translateZ(100px);
}
.box p:nth-child(4) {
background-color: rgba(118, 243, 237, 0.356);
/* 下面 */
transform:rotateX(90deg) translateZ(-100px);
}
.box p:nth-child(5) {
background-color: rgba(118, 156, 243, 0.356);
/* 左面 */
transform:rotateY(90deg) translateZ(-100px);
}
.box p:nth-child(6) {
background-color: rgba(197, 118, 243, 0.356);
/* 右面 */
transform:rotateY(90deg) translateZ(100px);
}
</style>
</head>
<body>
<div class="box">
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
</div>
</body>
</html>
6
收起
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星