老师帮忙看下代码对吗?有什么需要优化的地方
来源:2-12 空间移动
我代码么问题
2021-10-01 21:23:35
<!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>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
width: 200px;
height: 200px;
margin: 100px auto;
/* border: 1px solid black; */
position: relative;
perspective: 300px;
}
.box p {
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 200px;
}
.box p:nth-child(1) {
background-color: rgb(131, 54, 93);
/* 前面 */
transform: translateZ(100px)
}
.box p:nth-child(2) {
background-color: rgb(27, 20, 56);
/* 顶面 */
transform: rotateX(90deg) translateZ(100px);
}
.box p:nth-child(3) {
background-color: rgb(202, 173, 173);
/* 背面 */
transform: rotateX(900deg) translateZ(100px);
}
.box p:nth-child(4) {
background-color: rgb(37, 34, 34);
/* 底面 */
transform: rotateX(-90deg) translateZ(100px);
}
.box p:nth-child(5) {
background-color: rgb(0, 180, 126);
/* 侧面 */
transform: rotateY(90) translateZ(100px);
}
.box p:nth-child(6) {
background-color: rgb(117, 131, 54);
transform: rotateY(1deg) translateZ(3px);
}
</style>
</head>
<body>
<div class="box">
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
</div>
</body>
</html>
1回答
好帮手慕久久
2021-10-06
同学你好,代码需要做如下优化:
1、背面,旋转180deg就行:
2、rotateY中的数值,要加单位:
3、侧面,旋转的角度和位移都不对,调整如下:
祝学习愉快!
相似问题
回答 1
回答 1
回答 1
回答 1
回答 2