Moritz
Moritz

Reputation: 93

CSS hover effect on image using Lightbox 2

I have a grid of images. When I hover the images I want a simple hover effect using a second image at the top and the ease-in-out transition. When I click on the image it opens a bigger version of it with Lightbox 2. I couldnt get the hover working...

HTML-Code of one picture and caption:

<div id="gallery">
    <div class="floated_img">
        <a href="images/placeholder_1.jpg" title="Name" data-lightbox="Box_1"><img src="images/placeholder.png">
        </a>
        <p>Name</p>
    </div>
</div>

CSS:

body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    text-align: center;
}

#gallery {
    padding-top: 10px;
    font-size: 0;
    margin: 0 auto;
    width: 58.5%;
    text-align: center;
    display: inline-block;
}

.floated_img {
    float: left;
    margin-left: 20px;
    margin-bottom: 30px;
    display: inline-block;
}

#gallery p {
    font-family: 'Roboto', Helvetica, Arial, sans-serif;
    font-weight: 300;
    font-size: 18px;
    color: #000;
    text-align: center;
}

Upvotes: 0

Views: 3894

Answers (1)

Moritz
Moritz

Reputation: 93

I finally figured it out! I used this CSS code for the bottom image:

{background-image: url(../images/placeholder.png);}

And then I replaced the placeholder.png from the html with the thumbnail-hover.png. Then I used a normal :hover on the thumbnail-hover.png (see "top"-class)

Here is the whole code:

HTML:

<div id="gallery">
    <div id="floated_img">
        <a href="images/placeholder_1.jpg" title="Name" data-lightbox="Box_1">
            <img class="top" src="images/thumbnail-hover.png">
        </a><p>Name</p>
    </div>
</div>

CSS:

#gallery {
    padding-top: 10px;
    font-size: 0;
    margin: 0 auto;
    width: 58.5%;
    text-align: center;
    display: inline-block;
}

#floated_img {
    float: left;
    height: 200px;
    width: 200px;
    margin-left: 20px;
    margin-bottom: 30px;
    margin-top: 20px;
    display: inline-block;
    background-image: url(../images/placeholder.png);
}

#floated_img img.top {
    float: left;
    height: 200px;
    width: 200px;
    display: inline-block;
    opacity: 0;
    transition: opacity 500ms ease-in-out;
}

#floated_img img.top:hover {
    opacity: 0.4;
}

Upvotes: 1

Related Questions