CSS3
3D转换-Y轴2面翻转的盒子
源码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* body {
perspective: 200px;
} */
.box {
position: relative;
width: 200px;
height: 200px;
margin: 100px auto;
cursor: pointer;
transition: all 0.6s;
/* 让子元素保持3D立体空间环境 */
transform-style: preserve-3d;
}
.box:hover {
transform: rotateY(180deg);
}
.front,
.back {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 20px;
color: #fff;
border-radius: 50%;
text-align: center;
line-height: 200px;
}
.front {
background-color: red;
}
.back {
background-color: #f40;
/* 先旋转180度 */
transform: rotateY(180deg);
}
</style>
</head>
<body>
<div class="box">
<div class="front">欢迎来到</div>
<div class="back">王者荣耀</div>
</div>
</body>
</html>
运行结果:
参考资料
[1] CSS3 3D转换 | 菜鸟教程
[2] MDN | translateY