css - 悬停时的图像和颜色叠加

标签 css

我很难在将鼠标悬停在图像上时显示颜色叠加层(和图像)。

基本上,用户应该看到这个叠加层(在下面的 2 中分开):

enter image description here

我有以下 HTML 片段:

<ul id="Grid">
    <li class="mix category_1 mix_all" style="display: inline-block; opacity: 1;">
        <img src="http://i.imgur.com/J4PaouI.jpg" alt="#">
    </li>
</ul>

这是特定的 CSS(还有一个 z-index 只是为了确定):

.mix_all:hover {
    background: url(http://i.imgur.com/0lu7dWs.png) no-repeat center !important;
    background-color: #de6573 !important;
    z-index: 99999999;
}
#Grid .mix {
    width: 200px;
    height: 200px;
    margin-bottom: 20px;
}
.mix.mix_all img {
    max-height: 200px;
    max-width: 200px;
}

这是 fiddle 的链接:

http://jsfiddle.net/t2ea9/

最佳答案

这是一个正确的版本:http://jsfiddle.net/maximgladkov/b2twr/1/

您应该添加一个带有 position: absolute 的附加元素并显示它。

HTML

<ul id="Grid">
    <li class="mix category_1 mix_all">
        <img src="http://i.imgur.com/J4PaouI.jpg" alt="#" />
        <div class="overlay"></div>
    </li>
</ul>

CSS

.mix_all {
    position: relative;
}

.mix_all .overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.mix_all:hover .overlay {
    background: url(http://i.imgur.com/0lu7dWs.png) no-repeat center !important;
    background-color: #de6573 !important;
    z-index: 99999999;
}

关于css - 悬停时的图像和颜色叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35984531/

相关文章:

PHP - 获取正则表达式结果的行号

jquery - 使用 e.target == this 指定 hitbox

javascript - 使用 Grunt 编译 less 文件

HTML CSS : Have two block elements side by side

javascript - 单击一个图标,它会通过 javascript 显示一个下拉菜单

html - 保持可扩展 div 的纵横比

javascript - 锚定在两列行中的可滚动 DIV 内

html - 垂直对齐列表项中的文本

asp.net-mvc - MVC3、CSS3 - 无法在文本框中获取样式

html - 使用 :before and :after elements to fill remaining space of text element