两个子盒子都添加backface-visibility: hidden;
backface-visibility: hidden;指定当元素背朝观察者时是否可见
全部代码
<style>
.box {
perspective: 500px;
position: relative;
width: 300px;
height: 300px;
margin: 100px auto;
transition: all 2s;
transform-style: preserve-3d;
}
.front,
.back {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 50%;
font-size: 30px;
text-align: center;
line-height: 300px;
transform-style: preserve-3d;
backface-visibility: hidden;
}
.front {
background-color: aqua;
z-index: 1;
}
.back {
background-color: blueviolet;
transform: rotateY(180deg);
}
.box:hover {
transform: rotateY(180deg);
}
</style>
<body>
<div class="box">
<div class="front">黑马程序员</div>
<div class="back">我在这里等你</div>
</div>
</body>
效果展示