图像不淡入?CSS

py49o6xq  于 2023-01-22  发布在  其他
关注(0)|答案(1)|浏览(119)

我正试着让覆盖层淡入,但现在它是一个即时的变化
超文本:

<div class="image-container">
    <img src="https://basicfishkeeping.com/wp-content/uploads/2023/01/Freshwater-Aquatic-Background-7.png" class="before">
    <img src="https://basicfishkeeping.com/wp-content/uploads/2023/01/Freshwater-Aquatic-Background-8.png" class="after">
</div>

CSS:

.image-container {
    position: relative;
    width: 250px;
    height: 250px;
}
.image-container .before {
    width: 100%;
    height: 100%;
}
.image-container .after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    opacity: 0;
    transition: 0.5s;
}
.image-container:hover .after {
    display: block;
    opacity: 1;
}

尝试在Wordpress上运行它,并立即更改为第二个图像,而不是淡入淡出

c0vxltue

c0vxltue1#

以下是渐入过渡:

.image-container {
    position: relative;
    width: 250px;
    height: 250px;
}
.image-container .before {
    width: 100%;
    height: 100%;
}
.image-container .after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    opacity: 0;
    transition: 0.5s;
}
.image-container:hover .after {
    display: block;
}

.after:hover {
    transition: 0.5s;
    opacity: 1;
}

相关问题