css写一个立方体
效果图
实现步骤
(1)父元素设置
确定景深,景深基点位置,以及产生一个三维空间
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
padding: 0; margin: 0;}
ul{
list-style: none;}
/*给ul宽高并居中*/
#box{
width: 300px;
height: 300px;
border: 1px solid black;
margin: 20px auto;
perspective: 300px;/*景深*/
perspective-origin: right top;/*景深基点位置*/
}
#box ul{
width: 100px;
height: 100px;
margin: 100px auto;
position: relative;
transition: all 4s;
transform-style: preserve-3d;/*产生一个三维空间*/
transform-origin: center center -50px;/*确定旋转中心*/
}
</style>
<