这里我有一个容器内的图像和描述
我希望当我翻转容器时,隐藏图像并显示说明,因此我在图像上使用了 backface-visibility: hidden;
,但它不起作用。
.scene {
width: 200px;
height: 150px;
}
.container {
width: 100%;
height: 100%;
position: relative;
transition: transform .4s;
}
.image,
.description {
position: absolute;
width: 100%;
height: 100%;
}
.scene:hover .container {
transform: rotateY(180deg);
}
.image {
backface-visibility: hidden;
}
<div class="scene">
<div class="container">
<div class="description">
Kurapica is an anime character.
</div>
<img class="image" src="https://preview.ibb.co/bO30hn/kurapika.jpg" alt="Kurapica">
</div>
</div>
答案 0 :(得分:2)
backface-visibilty:hidden
上的{p> .image
无效,因为您轮换.container
而非.image
...
所以旋转.image
和.description
代替.container
以获得所需的效果
.scene {
width: 200px;
height: 150px;
}
.container {
width: 100%;
height: 100%;
position: relative;
}
.image,
.description {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
transition: transform .4s;
}
.description {
transform: rotateX(-180deg);
background: red;
display: flex;
align-items: center;
text-align: center;
}
.scene:hover .image {
transform: rotateX(180deg);
}
.scene:hover .description {
transform: rotateX(0deg);
}
<div class="scene">
<div class="container">
<div class="description">
Kurapica is an anime character.
</div>
<img class="image" src="https://preview.ibb.co/bO30hn/kurapika.jpg" alt="Kurapica">
</div>
</div>
答案 1 :(得分:1)
因为您必须在指定backface-visibility
:
.scene {
width: 200px;
height: 150px;
}
.container {
width: 100%;
height: 100%;
position: relative;
}
.image,
.description {
position: absolute;
width: 100%;
height: 100%;
transition: transform .4s;
}
.scene:hover .container .image {
transform: rotateX(180deg);
}
.image {
backface-visibility: hidden;
}
&#13;
<div class="scene">
<div class="container">
<div class="description">
Kurapica is an anime character.
</div>
<img class="image" src="https://preview.ibb.co/bO30hn/kurapika.jpg" alt="Kurapica">
</div>
</div>
&#13;
答案 2 :(得分:0)
您还必须设置转换后的元素backface-visibility
:
.scene:hover .container {
transform: rotateX(180deg);
backface-visibility: hidden;
}