这个案例最重要的是 x,y,z轴的旋转
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3D导航栏</title>
<style>
* {
margin: 0;
padding: 0;
}
ul {
margin: 100px;
}
ul li {
float: left;
margin: 5px;
width: 120px;
height: 35px;
list-style: none;
/*一会我们需要给box 旋转 也需要透视 干脆给li加 里面的子盒子都有透视效果*/
perspective: 500px;
}
.box {
position: relative;
width: 100%;
height: 100%;
color: #fff;
text-align: center;
line-height: 35px;
transform-style: preserve-3d;
transition: all .4s;
}
.box:hover {
transform: rotateX(90deg);
}
.front,
.bottom {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.front {
background-color: pink;
transform: translateZ(17.5px);
}
.bottom {
background-color: purple;
/*这个x轴一定是负值*/
/*如果2D效果中,既有移动又有旋转等其他效果*/
transform: translateY(17.5px) rotateX(-90deg);
}
</style>
</head>
<body>
<ul>
<li>
<div class="box">
<div class="front">翻开我</div>
<div class="bottom">我爱你</div>
</div>
</li>
<li>
<div class="box">
<div class="front">翻开我</div>
<div class="bottom">我爱你</div>
</div>
</li>
<li>
<div class="box">
<div class="front">翻开我</div>
<div class="bottom">我爱你</div>
</div>
</li>
<li>
<div class="box">
<div class="front">翻开我</div>
<div class="bottom">我爱你</div>
</div>
</li>
<li>
<div class="box">
<div class="front">翻开我</div>
<div class="bottom">我爱你</div>
</div>
</li>
<li>
<div class="box">
<div class="front">翻开我</div>
<div class="bottom">我爱你</div>
</div>
</li>
</ul>
</body>
</html>