html - 将鼠标悬停在图像上时显示带有半透明颜色叠加层的标题

标签 html css hover opacity

我使用以下代码在将鼠标悬停在图像上时显示带有半透明红色覆盖层的标题:

HTML:

<a href="http://www.domain.com/">
    <div class="thumb">
        <img src="http://www.domain.com/thumbnail.jpg" width="100" height="100" alt="" />
        <div>
            <span>Caption</span>
        </div>
    </div>
</a>

CSS:

.thumb {
    position: relative;
}
.thumb div {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: #fe0000;
    color: #fff;
    opacity: 0;
    transition: opacity 0.5s;
}
.thumb img {
    display: block;
}
.thumb div span {
    display: block;
    position: absolute;
    bottom: 10px;
    left: 10px;
    font-size: 30px;
}

.thumb:hover div {
    opacity: 0.3;
}

此代码的问题在于标题也是半透明的。我想知道如何更改它以使标题不透明。

任何想法将不胜感激

最佳答案

你可以设置

background: rgba(255,0,0,0.3);

然后

opacity: 1;

在分区中

像这样:http://jsfiddle.net/EUUMX/

关于html - 将鼠标悬停在图像上时显示带有半透明颜色叠加层的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24600487/

相关文章:

html - a 标签内的不同悬停行为。 IE 8+ 中的问题

html - 在 TD 中使用高度 100% 会削减 FF 中的内容

python - 我应该使用 Screen Scrapers 还是 API 从网站读取数据

html - 是否有任何选项可以动态调整绝对定位 child 的高度到他的相对 parent ?

javascript - 向下滚动网站时固定标题

css - 使用 css3 过渡定位多个 css 元素

html - 如何将内容包裹在图像周围?

html - 子 div 不会扩展到父 div 的全高

css - 覆盖 css hover 让它什​​么都不做

javascript - 根据其他 div 的悬停触发完全独立的 div