使用Lightbox 2

时间:2015-08-30 13:37:59

标签: html css hover lightbox

我有一个图像网格。当我悬停图像时,我想要一个简单的悬停效果,使用顶部的第二个图像和易于进入的过渡。当我点击图片时,它会用Lightbox 2打开它的更大版本。我无法让悬停工作......

一张图片和标题的HTML代码:

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

1 个答案:

答案 0 :(得分:1)

我终于明白了!我将这个CSS代码用于底部图像:

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

然后我用thumb-hover.png替换了html中的placeholder.png。然后我使用了法线:将鼠标悬停在thumbnail-hover.png上(参见“top”-class)

以下是整个代码:

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