圖片庫Image Gallery(Thumbnails)

 

一個基本的圖片庫範例如下,

<!DOCTYPE html>
<html>
<head>
<style>
div.img {
    margin: 5px;
    border: 1px solid #ccc;
    float: left;
    width: 180px;
}	

div.img:hover {
    border: 1px solid #777;
}

div.img img {
    width: 100%;
    height: auto;
}

div.desc {
    padding: 15px;
    text-align: center;
}
</style>
</head>
<body>

<div class="img">
  <a target="_blank" href="img_fjords.jpg">
    <img src="img_fjords.jpg" alt="Trolltunga Norway" width="300" height="200">
  </a>
  <div class="desc">Add a description of the image here</div>
</div>

<div class="img">
  <a target="_blank" href="img_forest.jpg">
    <img src="img_forest.jpg" alt="Forest" width="300" height="200">
  </a>
  <div class="desc">Add a description of the image here</div>
</div>

<div class="img">
  <a target="_blank" href="img_lights.jpg">
    <img src="img_lights.jpg" alt="Northern Lights" width="300" height="200">
  </a>
  <div class="desc">Add a description of the image here</div>
</div>

<div class="img">
  <a target="_blank" href="img_mountains.jpg">
    <img src="img_mountains.jpg" alt="Mountains" width="300" height="200">
  </a>
  <div class="desc">Add a description of the image here</div>
</div>

</body>
</html>

上例是使用float來做排列,但我個人是使用display:inline-block,

使用display:inline-block可以達到模組化效果,但你要使用float可以,

要看你怎麼用,只要你會處理就好。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>JS Bin</title>
    <style>
        .img {
            display: inline-block;
            width: 200px;
            border: 1px solid;
        }

        img {
            width: 100%;
        }
    </style>
</head>
<body>
    <div>
        <p>Add a description of the image here</p>
    </div>

    <div class="img">
        <img src="http://www.w3schools.com/css/img_fjords.jpg">
        <div class="desc">Add a description of the image here</div>
    </div>

    <div class="img">
        <img src="http://www.w3schools.com/css/img_fjords.jpg">
        <div class="desc">Add a description of the image here</div>
    </div>

    <div class="img">
        <img src="http://www.w3schools.com/css/img_fjords.jpg">
        <div class="desc">Add a description of the image here</div>
    </div>

    <div>
        <p>Add a description of the image here</p>
    </div>
</body>
</html>

 

參考資料:

CSS Image Gallery

Tutorial 4 - Floating an image thumbnail gallery - all steps combined

menucool.com/jquery-slider

10 Amazing Responsive Image Galleries