CSS中的3D旋转是一种新颖的视觉展示方式,可以给网页带来更加生动、立体的效果。那么,如何设置CSS中的3D旋转呢?
.box{
width: 200px;
height: 200px;
position: relative;
transform-style: preserve-3d;
}
.box:hover{
transform: rotateY(180deg);
}
.box .front, .box .back{
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.box .front{
background: #f1c40f;
}
.box .back{
transform: rotateY(180deg);
background: #2ecc71;
} 以上是一个简单的3D旋转设置示例。首先,在外部盒子.box中设置了transform-style: preserve-3d,表示子元素继承父元素的3D属性。然后,当鼠标移动到盒子上方时,通过:hover伪类触发rotateY(180deg)的3D旋转效果。
接着,设置子元素的正反两面的样式。其中,backface-visibility: hidden可以解决默认情况下反面直接隐藏的问题。
最后,我们可以尝试修改rotateY的角度,改变旋转方向,或是整合其他3D效果,来展现不同的效果。