如何图像库中心?

时间:2015-10-21 04:14:44

标签: html css gallery

我使用以下代码创建了一个图片库:http://www.w3schools.com/css/css_image_gallery.asp

它将它与左对齐。我在图库中有9张图片。我想要做的是在页面中央对齐3行3列图像,两边都有边距,但我似乎无法弄明白。

1 个答案:

答案 0 :(得分:0)

试试这个。 。您可以更改#container

的宽度
<!DOCTYPE html>
<html>
<head>
<style>
#container{
width: 500px; 
margin: 0 auto;

}
div.img {
    margin: 5px;
    padding: 5px;
    border: 1px solid #0000ff;
    height: auto;
    width: auto;
    float: left;
    text-align: center;
}   

div.img img {
    display: inline;
    margin: 5px;
    border: 1px solid #ffffff;
}

div.img a:hover img {
    border: 1px solid #0000ff;
}

div.desc {
  text-align: center;
  font-weight: normal;
  width: 120px;
  margin: 5px;
}
</style>
</head>
<body>
<div id="container">
<div class="img">
 <a target="_blank" href="klematis_big.htm"><img src="klematis_small.jpg" alt="Klematis" width="110" height="90"></a>
 <div class="desc">Add a description of the image here</div>
</div>
<div class="img">
 <a target="_blank" href="klematis2_big.htm"><img src="klematis2_small.jpg" alt="Klematis" width="110" height="90"></a>
 <div class="desc">Add a description of the image here</div>
</div>
<div class="img">
 <a target="_blank" href="klematis3_big.htm"><img src="klematis3_small.jpg" alt="Klematis" width="110" height="90"></a>
 <div class="desc">Add a description of the image here</div>
</div>
<div class="img">
 <a target="_blank" href="klematis4_big.htm"><img src="klematis4_small.jpg" alt="Klematis" width="110" height="90"></a>
 <div class="desc">Add a description of the image here</div>
</div>
<div>
</body>
</html>