<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>立体盒子</title>
<style>
.box{
height:200px;
width: 200px;
margin: 100px auto;
position: relative;
transform: rotate3d(1,1,0,-15deg);
/*让子元素保留3d变换效果*/
transform-style: preserve-3d;
/*添加透视景深效果*/
perspective: 3000px;
/*设置透视的观察角度*/
perspective-origin: 150px 150px;
}
.box > div{
width: 200px;
height: 200px;
position: absolute;
opacity: 0.6;
}
.front{
background-color: red;
/*变化完毕后会回到原始状态*/
transform: translateZ(100px);
}
.back{
background-color: yellowgreen;
transform: translateZ(-100px) rotateY(180deg);
}
.left{
background-color: grey;
/*移动加旋转*/
transform: translateX(-100px) rotateY(-90deg);
}
.right{
background-color: magenta;
transform: translateX(100px) rotateY(90deg);
}
.top{
background-color: deepskyblue;
transform: translateY(-100px) rotateX(90deg);
}
.bottom{
background-color: peachpuff;
transform: translateY(100px) rotateX(-90deg);
}
</style>
</head>
<body>
<div class="box">
<div class="front">front</div>
<div class="back">back</div>
<div class="left">left</div>
<div class="right">right</div>
<div class="top">top</div>
<div class="bottom">bottom</div>
</div>
</body>
</html>
正方体实例
最新推荐文章于 2024-08-28 15:18:58 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)