gpt4 book ai didi

css - 在::before 伪元素上使用 CSS 过渡

转载 作者:太空狗 更新时间:2023-10-29 12:23:45 24 4
gpt4 key购买 nike

.posts .img-hover:before {
content: '';
display: block;
opacity: 0;
-webkit-transition: opacity 1.2s ease;
-moz-transition: opacity 1.2s ease;
-ms-transition: opacity 1.2s ease;
-o-transition: opacity 1.2s ease;
transition: opacity 1.2s ease-out;
}
.posts .img-hover:hover:before {
content: '';
display: block;
background: url("img/Texture1.png");
width: 320px;
/* image width */
height: 220px;
/* image height */
position: absolute;
top: 13px;
right: 2px;
opacity: 1;
}
<div class="posts">
<a href="#">
<h2 class="postname">
Travel Flashback #1 </h2>
</a>
<a class="img-hover" href="#">
<img width="960" height="720" src="http://.." class="img-hover" alt="" />
</a>
</div>

这段代码有一个问题。如您所见,我想过渡到伪元素::before,它有 bkg img。

当我将鼠标悬停在上面时,过渡会很顺利,但是当我离开鼠标时,bkg img 会立即消失而没有过渡。

你能给我点建议吗?

最佳答案

在悬停时,您可能只需要与过渡相关的 css,而不是伪元素的实际样式。试试这个

.posts .img-hover:before {
content: '';
display: block;
background: url("img/Texture1.png");
width: 320px; /* image width */
height: 220px; /* image height */
position: absolute;
top: 13px;
right: 2px;
opacity: 0;
-webkit-transition: opacity 1.2s ease;
-moz-transition: opacity 1.2s ease;
-ms-transition: opacity 1.2s ease;
-o-transition: opacity 1.2s ease;
transition: opacity 1.2s ease-out;
}
.posts .img-hover:hover:before{
opacity: 1;
}

关于css - 在::before 伪元素上使用 CSS 过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39489039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com