立体呈现-第二十五天
作者:互联网
立体呈现
目标:使用tranform-style:preserve-3d呈现立体图形
- 呈现立体图形步骤
- 盒子父元素添加transform-style:preserve-3d;
- 按需求设置子盒子的位置(位移或旋转)
- 注意
- 空间内,转换元素都有自己独立的坐标轴,互不干扰
实现正方体
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
width: 200px;
height: 200px;
position: relative;
margin: 200px auto;
/* 添加透视 */
perspective: 1000px;
/* 保留子元素的三维变化效果 */
transform-style: preserve-3d;
transform: rotate3d(1,1,0,-30deg);
}
.face{
width: 200px;
height: 200px;
position: absolute;
left: 0;
top: 0;
background-color: rgba(255, 0, 0, 0.4);
}
.face:nth-of-type(1){
transform: translateZ(100px);
}
.face:nth-of-type(2){
transform: translateZ(-100px) rotateY(180deg);
}
.face:nth-of-type(3){
transform: translateX(-100px) rotateY(-90deg);
}
.face:nth-of-type(4){
transform: translateX(100px) rotateY(90deg);
}
.face:nth-of-type(5){
transform: translateY(-100px) rotateX(90deg);
}
.face:nth-of-type(6){
transform: translateY(100px) rotateX(-90deg);
}
</style>
</head>
<body>
<div class="box">
<div class="face" style="background: green;">1</div>
<div class="face" style="background: pink;">2</div>
<div class="face" style="background: blue;">3</div>
<div class="face" style="background: yellow;">4</div>
<div class="face" style="background: white;">5</div>
<div class="face" style="background: black;">6</div>
</div>
</body>
</html>
标签:呈现,100px,transform,face,立体,nth,第二十五,type,200px 来源: https://www.cnblogs.com/cm666/p/16227227.html