先看效果图
<!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>
body {
perspective: 500px;
}
.box {
position: relative;
width: 300px;
height: 300px;
margin: 100px auto;
transition: all 1s linear;
/* 让背面保留立体空间 */
transform-style: preserve-3d;
}
.box:hover {
transform: rotateY(180deg);
}
.front,
.back {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
font-size: 30px;
color: rgb(255, 254, 254);
text-align: center;
line-height: 300px;
/* 把后面的隐藏 */
backface-visibility: hidden;
}
.front {
background-color: pink;
/* z-index: 1; */
}
.back {
background-color: rgb(0, 187, 255);
/* 背靠背 */
transform: rotateY(180deg);
/* 去除影藏,在上面加translateZ(1px)也会实现,但会有小露出 */
}
</style>
</head>
<body>
<div class="box">
<div class="front">猜猜我喜欢谁?</div>
<div class="back">我喜欢你</div>
</div>
</body>
</html>