HTML5+CSS3 3D旋转案例
HTML5+CSS3 3D旋转案例
案例1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Document</title>
<style>
.box {
perspective: 500px;
position: relative;
margin: 100px auto;
width: 200px;
height: 300px;
transition: all 1s;
transform-style: preserve-3d;
}
.box:hover {
transform: rotateY(60deg);
}
.box div {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: orange;
}
.box div:last-child {
background-color: purple;
transform: rotateX(60deg);
}
</style>
</head>
<body>
<div class="box">
<div></div>
<div></div>
</div>
</body>
</html>
效果:
案例2
3D旋转立方体
```html
<!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>