图库水平显示相同大小的图像

时间:2017-04-06 11:05:44

标签: html css image gallery

我正在研究HTML和CSS,我很难水平对齐图像而不是垂直对齐。

我尝试将它们显示在内联块中并且内联它们都不起作用。而且我也希望我的图像具有相同的尺寸。

这是我的HTML代码:

#gallery {
  width: 500px;
  overflow: hidden;
  position: relative;
  z-index: 1;
  margin: 100px auto;
  display: inline;
}

#gallery img {
  width: 50%;
  height: auto;
  border: 5px solid #FFFFFF;
  margin: 10px;
  box-sizing: border-box;
  margin: 0 auto;
  padding: 0;
}
<div id="gallery">
  <a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee"><img src="images/gallery1.png"></a>
  <a href="images/gallery2.png" data-lightbox="roadtrip" data-title="Ian and Vee"><img src="images/gallery2.png"></a>
  <a href="images/gallery3.png" data-lightbox="roadtrip" data-title="Ian and Vee"><img src="images/gallery3.png"></a>
  <a href="images/gallery4.png" data-lightbox="roadtrip" data-title="Ian and Vee"><img src="images/gallery4.png"></a>
  <a href="images/gallery5.png" data-lightbox="roadtrip" data-title="Ian and Vee"><img src="images/gallery5.png"></a>
  <a href="images/gallery6.png" data-lightbox="roadtrip" data-title="Ian and Vee"><img src="images/gallery6.png"></a>
  <script src="lightbox2-master/dist/js/lightbox-plus-jquery.js"></script>
</div>

2 个答案:

答案 0 :(得分:0)

试试这个:

div.gallery {
  margin: 5px;
  border: 1px solid #ccc;
  float: left;
  width: 180px;
}

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

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

div.desc {
  padding: 15px;
  text-align: center;
}
<div class="gallery">
  <a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
    <img src="images/gallery1.png" width="600" height="400">
  </a>
</div>
<div class="gallery">
  <a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
    <img src="images/gallery1.png" width="600" height="400">
  </a>
</div>
<div class="gallery">
  <a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
    <img src="images/gallery1.png" width="600" height="400">
  </a>
</div>
<div class="gallery">
  <a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
    <img src="images/gallery1.png" width="600" height="400">
  </a>
</div>
<div class="gallery">
  <a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
    <img src="images/gallery1.png" width="600" height="400">
  </a>
</div>
<div class="gallery">
  <a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
    <img src="images/gallery1.png" width="600" height="400">
  </a>
</div>

答案 1 :(得分:0)

更简单的答案。在图像中添加一个浮动。

#gallery {
  width: 500px;
  overflow: hidden;
  position: relative;
  z-index: 1;
  margin: 100px auto;
  display: inline;
}

#gallery img {
  float: left;
  width: 50%;
  height: auto;
  border: 5px solid #FFFFFF;
  margin: 10px;
  box-sizing: border-box;
  margin: 0 auto;
  padding: 0;
}