我试图使用CSS创建一个3D立方体,但并不是立方体的所有侧面都能正常显示
我的立方体的左侧、右侧和顶部根本不显示
仅3D立方体的前部、底部和后部。
我试图改变立方体的大小,我试图改变变换属性和角度,但都不起作用
任何帮助都会很棒。
这是我的CSS代码,很抱歉它太长了
.container {
width: 400px;
height: 400px;
border: 2px solid white;
border-radius: 4px;
display: flex;
justify-content: center;
align-items: center;
perspective: 800px;
perspective-origin: top right;
}
.cube {
position: relative;
width: 200px;
height: 200px;
transform-style: preserve-3d;
border: 2px solid white;
animation: cubeRotate 5s linear infinite;
}
.face {
position: absolute;
width: 200px;
height: 200px;
opacity: 0.9;
line-height: 100px;
text-align: center;
font-size: 1.4rem;
}
.front {
background-color: lightblue;
transform: translateZ(100px);
}
.backward {
background-color: lightgreen;
transform: translateZ(-100px);
}
.left {
background-color: peru;
transform: rotateY('-90deg') translateZ(-100px);
}
.right {
background-color: blueviolet;
transform: rotateY('90deg') translateZ(100px) ;
}
.top {
background-color: brown;
transform: rotateX('90deg') translateZ(100px);
}
.bottom {
background-color: aqua;
transform: translateZ(100px) rotateX('-90deg');
}
@keyframes cubeRotate {
from {
transform: rotateY(0deg)
}
to {
transform: rotateY(360deg)
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="container">
<div class="cube">
<div class="face front">Front </div>
<div class="face left">Left </div>
<div class="face right">Right </div>
<div class="face backward">Backward</div>
<div class="face top">Top</div>
<div class="face bottom">Bottom</div>
</div>
</div>
</body>
</html>