锦方的个人网页 · 如果有一天你突然想起了我


css 图片

下面是完整的响应式图片画廊示例代码:

<!DOCTYPE html>
<html>
<head>
    <style>
         /*---1-------------------------------------------
            	通用
        -------------------------------------------------*/    
        div.gallery{
            border: 1px solid #ccc;
            box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
        }
        div.gallery:hover{
            border: 1px solid #777;
        }
        div.gallery img{
            width:100%;
            height: auto;
        }
        div.desc{
            padding: 15px;
            text-align: center;
            word-wrap: break-word;
        }
        *{
            box-sizing: border-box;
        }
        .responsive{
            padding: 0 6px;
            float: left;
            width:24.99999%
        }
        @media only screen and (max-width:700px){
            .responsive{
                width:49.99999%;
                margin: 6px 0;
            }
        }
        @media only screen and (max-width:500px){
            .responsive{
                width:100%;
            }
        }
        .clearfix:after{
            content:"";
            display: table;
            clear: both;
        }

        /*---2-------------------------------------------
            	给第一张图片加一个悬停的重叠
        -------------------------------------------------*/   
        .container{
            position: relative;
            width:100%;
        }
        .image{
            display:block;
            width:100%;
            height: auto;
        }
        .overlay{
            position: absolute;
            top: 0;
            bottom: 0;
            left:0;
            right: 0;
            height: 100%;
            width:100%;
            opacity: 0;
            transition: .5s ease;
            background-color: red;
        }
        .container:hover .overlay{
            opacity: 1;
        }
        .text{
            color: white;
            font-size: 20px;
            position: absolute;
            top: 50%;
            left:50%;
            transform: translate(-50%,-50%);
        }
    </style>
</head>
<body>
<div class="responsive">
        <div class="container gallery">
        <a target="_blank" href="source/images/loge.jpg">
            <img src="source/images/loge.jpg" alt="只是一个悬停的重叠的图片示例" class="image" width="300" height="300">
        </a>
        <div class="desc">悬停的重叠的图片</div>
        <div class="overlay">
            <div class="text">侬好</div></div>
    </div>
</div>
<div class="responsive">
    <div class="gallery ">
        <a target="_blank" href="https://example.com">
            <img src="source/images/loge.jpg" alt="这是一个把图像作为链接的图片" width="300" height="300">
        </a>
        <div class="desc">这是一个把图像作为链接的图片</div>
    </div>
</div>
<div class="responsive">
    <div class="gallery">
        <a target="_blank" href="source/images/loge.jpg">
            <img style="opacity:0.5;"src="source/images/loge.jpg" alt="" width="300" height="300">
        </a>
        <div class="desc">opacity过的图片</div>
    </div>
</div>

</body>
</html>