<!DOCTYPE html>
<html>
<head>
<title>cssBox</title>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
#stage{ /*舞台元素,该元素作为舞台,不用进行3d操作,舞台内部的元素需设置为3d元素,包括容器和容器内的元素*/
position: relative;
height: 800px;
background-color: #D4D4D4;
perspective: 3500px; /*使得舞台子元素变为透视元素, 即遵循近大远小,参考WebGL的透视相机*/
perspective-origin: 0 0; /*设置相机相对舞台的位置, 这里设置未左上角,个人理解是相机发射垂直射线到stage形成的点在左上角*/
}
#container{
width: 500px;
height: 500px;
position: absolute;
/*使得容器居中放置*/
margin-left: calc(50% - 250px);
margin-top: 150px;
transition: all ease-in-out 1s;
/*这步操作很关键,给容器加入3d效果,这时候容器内部的元素(即容器子元素),形成3d关系,若无此操作,经过3d变换,空间是乱的*/
transform-style: preserve-3d;
/*设置容器进行3d变换的中心点,即WebGL里的物体中心点,所有变换的会围绕改点进行,尤其是旋转最为明显,这里设置的点的位置刚好在正方体的最中心*/
transform-origin: ce
利用css3实现3D立方体旋转
最新推荐文章于 2022-10-11 10:13:03 发布