您的位置:首页 > Web前端 > CSS

CSS 3D旋转 hover 后设置transform 是相对于正常位置

2016-05-21 19:25 603 查看
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style type="text/css">
.nav{
width: 980px;
margin: 50px auto;
background-color: #fdfdfd;
border: 1px #ccc solid;
}
.nav:after{
clear: both;
display: block;
overflow: hidden;
content: "";
}
.nav .item{
width:200px;
height: 100px;
margin-right: 5px;
float: left;
perspective:400px;
}
.nav .item a{
display: block;
height: 100px;
text-decoration: none;
transition:all .5s;
transform-style:preserve-3d;
}
.nav .item a p{
height: 100px;
margin:0;
line-height: 100px;
color: #fff;
text-align:center;
font-size: 20px;
font-family: "Microsoft Yahei";
border-radius: 2px;
transition:all .5s;
}

.nav .item a p:first-child{
background-color: #090;
transform:translateZ(50px);

}
.nav .item a p:last-child{
background-color: #009;
/*这样会向结果方向走50px像素*/
transform:translateZ(50px) rotateX(-90deg) ;
/*margin-top: -50px;*/
}
/*立体旋转是按面在转*/
.nav .item a:hover{
transform:rotateX(90deg);
}
/*这东西是基于正常位置,而不是动画的位置如(transform:translateZ(50px) rotateX(-90deg) ;)*/
.nav .item a:hover p:last-child{
margin-top: 0;
transform: translateZ(0) rotateX(-90deg);
}
</style>
<body>
<header class="nav">
<div class="item">
<a href="#">
<p>首页</p>
<p>Home</p>
</a>
</div>

<div class="item">
<a href="#">
<p>问答</p>
<p>Q & A</p>
</a>
</div>

<div class="item">
<a href="#">
<p>关于我们</p>
<p>About us</p>
</a>
</div>
</header>
</body>
</html>


  之前一直想不通,如下为什么旋转到上面后要再旋转-90deg。

/*这东西是基于正常位置,而不是动画的位置如(transform:translateZ(50px) rotateX(-90deg) ;)*/
.nav .item a:hover p:last-child{
margin-top: 0;
transform: translateZ(0) rotateX(-90deg);
}

另外rotateX(-90deg)是上边缘向屏幕外旋转,也就是顺时针。反之。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: