【发布时间】:2018-04-25 06:39:07
【问题描述】:
我正在尝试创建一个画廊页面,我必须在其中放置数量不定的图像。例如,假设我以这种方式放置 6 张图片:
<link href="/stylesheets/gallery_gen.css" media="screen" rel="stylesheet" type="text/css">
<div class="my-gallery-contain" itemscope itemtype="http://schema.org/ImageGallery">
<div class="my-gallery">
<figure class="my-gallery-fig" classitemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="/img/gallery/matera/4.jpg" itemprop="contentUrl" data-size="600x400">
<img src="/img/thumbs/matera/4.jpg" itemprop="thumbnail" alt="Image description" />
</a>
<!--<figcaption itemprop="caption description"><p class="galleryCap">Image caption</p></ figcaption>-->
</figure>
<figure class="my-gallery-fig" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="/img/gallery/matera/5.jpg" itemprop="contentUrl" data-size="600x400">
<img src="/img/thumbs/matera/5.jpg" itemprop="thumbnail" alt="Image description" />
</a>
</figure>
<figure class="my-gallery-fig" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="/img/gallery/matera/6.jpg" itemprop="contentUrl" data-size="600x400">
<img src="/img/thumbs/matera/6.jpg" itemprop="thumbnail" alt="Image description" />
</a>
</figure>
<figure class="my-gallery-fig" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="/img/gallery/matera/7.jpg" itemprop="contentUrl" data-size="600x400">
<img src="/img/thumbs/matera/7.jpg" itemprop="thumbnail" alt="Image description" />
</a>
</figure>
<figure class="my-gallery-fig" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="/img/gallery/matera/8.jpg" itemprop="contentUrl" data-size="600x400">
<img src="/img/thumbs/matera/8.jpg" itemprop="thumbnail" alt="Image description" />
</a>
</figure>
<figure class="my-gallery-fig" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
<a href="/img/gallery/matera/28.jpg" itemprop="contentUrl" data-size="600x400">
<img src="/img/thumbs/matera/28.jpg" itemprop="thumbnail" alt="Image description" />
</a>
</figure>
</div>
</div>
CSS:
.my-gallery-contain {
margin: -20px 0px -20px;
}
.my-gallery img {
width: 300px;
margin: 0;
padding: 0;
}
.my-gallery-fig {
margin: 2px;
height: 200px;
overflow: hidden;
display: inline-block;
}
但是,只有第一行的间距相等。我得到的结果是这个: https://i.imgur.com/XS6cerM.jpg
如果我有另一行,则只有前两行等距。最后一行总是不等间距的。
我该如何解决这个问题?
另一个问题:如果我想在图像和旁边的图像之间有 2px 的固定边距,我怎样才能让拇指自动调整大小以适应 div? (在我发布的scree中,第二行有右边距,但是图像应该自动调整大小以适应外部div,以便右侧图像的左边距与右边距相同左图)
【问题讨论】:
标签: html css image gallery thumbnails