<!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>
* {
margin: 0;
padding: 0;
}
.nav {
width: 800px;
margin: 200px auto;
list-style: none;
}
.nav li {
float: left;
margin-right: 15px;
width: 120px;
height: 50px;
}
.nav li a {
position: relative;
transform-style: preserve-3d;
display: block;
width: 100%;
height: 100%;
text-align: center;
text-decoration: none;
line-height: 50px;
color: #fff;
transition: all 1s;
}
.nav li span {
position: absolute;
left: 0;
top: 0;
display: block;
width: 100%;
height: 100%;
}
.nav li span:first-child {
transform: translateZ(25px);
background-color: green;
}
.nav li span:last-child {
background-color: orange;
transform: translateY(-50%) rotateX(90deg);
}
.nav li a:hover {
transform: rotateX(-90deg);
}
</style>
</head>
<body>
<ul class="nav">
<li>
<a href="#">
<span>首页</span>
<span>index</span>
</a>
</li>
<li>
<a href="#">
<span>首页</span>
<span>index</span>
</a>
</li>
<li>
<a href="#">
<span>首页</span>
<span>index</span>
</a>
</li>
</ul>
</body>
</html>
一定要记住3个坐标轴取值的正反:
-
X 轴 往右越大,是正值, 否则反之
-
Y 轴 往下越大,是正值,否则反之
-
Z轴 (指向我们)越大,是正值,否则反之