gpt4 book ai didi

html - 悬停时的字幕叠加

转载 作者:太空宇宙 更新时间:2023-11-04 03:10:32 26 4
gpt4 key购买 nike

我正在尝试实现一个简单的标题,该标题在悬停时显示在我的缩略图上。目的是让图片单独显示,然后在悬停时,图片淡出一点,标题淡入上方。

我遇到的问题是悬停效果很好,直到鼠标越过标题本身,然后将图像返回到 100% 不透明度

<a href="#" class="thumbnail">

<img src="img/placeholder1.jpg" alt="...">
<span>caption</span>
</a>

CSS

a.thumbnail {
border:none;
border-radius: none;
padding:0;
margin:0;
position: relative;
background: #222;
}

a.thumbnail img {
-webkit-transition: opacity 0.5s ease;
-moz-transition: opacity 0.5s ease;
-o-transition: opacity 0.5s ease;
transition: opacity 0.5s ease;
opacity: 1;
}


a.thumbnail img:hover {

opacity: 0.7;
}


a.thumbnail span {
color: #FFF;
position: absolute;
bottom: 40%;
width: 100%;
height: 20%;
padding: 10px;
opacity: 0;
-webkit-transition: opacity 0.5s ease;
-moz-transition: opacity 0.5s ease;
-o-transition: opacity 0.5s ease;
transition: opacity 0.5s ease;
}

a.thumbnail:hover span {
opacity: 1;
}

最佳答案

将图像悬停到父 div。这样,当鼠标悬停在标题上时,不透明度将保持不变,因为您仍将鼠标悬停在父级上。

   a.thumbnail:hover img {
opacity: 0.7;
}

* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
a.thumbnail {
border: none;
border-radius: none;
padding: 0;
margin: 0;
position: relative;
background: #222;
}
a.thumbnail img {
-webkit-transition: opacity 0.5s ease;
-moz-transition: opacity 0.5s ease;
-o-transition: opacity 0.5s ease;
transition: opacity 0.5s ease;
opacity: 1;
}
a.thumbnail:hover img {
opacity: 0.7;
}
a.thumbnail span {
color: #FFF;
position: absolute;
bottom: 40%;
left: 0;
width: 100%;
padding: 10px;
background: red;
opacity: 0;
-webkit-transition: opacity 0.5s ease;
-moz-transition: opacity 0.5s ease;
-o-transition: opacity 0.5s ease;
transition: opacity 0.5s ease;
}
a.thumbnail:hover span {
opacity: 1;
}
<a href="#" class="thumbnail">

<img src="http://lorempixel.com/output/city-q-c-200-200-4.jpg" alt="..." />
<span>caption</span>
</a>

关于html - 悬停时的字幕叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29608381/

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