如果对3D转换不熟悉可以先看:CSS – CSS3中3D转换相关属性讲解(translate3d,rotate3d,perspective,transform-style)
旋转立方体:鼠标经过盒子自动翻转出来下面,离开时翻转回去
<!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>
ul {
margin: 100px auto;
list-style: none;
}
ul li {
float: left;
perspective: 300px;
margin: 10px;
}
.box {
position: relative;
width: 100px;
height: 40px;
transition: all 0.4s linear;
transform-style: preserve-3d;
}
.box:hover {
transform: rotateX(90deg);
}
.front,
.bottom {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
line-height: 40px;
text-align: center;
font-size: 20px;
color: #fff;
}
.front {
background-color: orange;
transform: translateZ(20px);
}
.bottom {
background-color: purple;
transform: translateY(20px) 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>
</ul>
</body>
</html>