Yashar
Yashar

Reputation: 275

Image and Color Overlay on Hover

I'm having a hard time getting a color overlay (and image) to appear when hovering over an image.

Essentially, the user should see this overlay (which is separated in 2 below):

enter image description here

I have the following HTML snippet:

<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>

Here is the particular CSS (and a z-index just to be sure):

.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;
}

Here is a link to the fiddle:

http://jsfiddle.net/t2ea9/

Upvotes: 0

Views: 867

Answers (1)

Maksim Gladkov
Maksim Gladkov

Reputation: 3079

Here is a correct version: http://jsfiddle.net/maximgladkov/b2twr/1/

You should add an additional element with position: absolute and show it.

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;
}

Upvotes: 2

Related Questions