<分区>
我想问一下响应式画廊。
这就是我想做的一个例子。因此,如您所见,图像的大小不是固定的。它只是保存比例的缩略图。
我不确定它是如何工作的。我应该如何使我的响应式?
应该怎么做?如果有现成的解决方案,请告诉我。
谢谢。
<分区>
我想问一下响应式画廊。
这就是我想做的一个例子。因此,如您所见,图像的大小不是固定的。它只是保存比例的缩略图。
我不确定它是如何工作的。我应该如何使我的响应式?
应该怎么做?如果有现成的解决方案,请告诉我。
谢谢。
最佳答案
正如其他人所说,你可以使用砌体
演示: https://jsfiddle.net/2Lzo9vfc/193/
HTML
<div class="gallery">
<img src="http://placehold.it/450x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/250x150">
<img src="http://placehold.it/550x150">
<img src="http://placehold.it/150x150">
<img src="http://placehold.it/250x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/450x150">
</div>
JS
$('.gallery').masonry({
itemSelector: 'img',
columnWidth: 1,
});
或者你可以尝试像这样用 flexbox 做一些事情
演示: https://jsfiddle.net/2Lzo9vfc/194/
CSS
img {
margin: 5px;
flex: 1 0 auto;
}
.gallery {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: flex-start;
}
或者你可以使用 column
但我认为这个支持很差
演示: https://jsfiddle.net/2Lzo9vfc/197/
img {
display: inline-block;
margin: 10px;
width: 100%;
}
.gallery {
-moz-column-count: 3;
-webkit-column-count: 3;
column-count: 3;
-moz-column-gap: 1em;
-webkit-column-gap: 1em;
column-gap: 1em;
}
关于javascript - 响应式图库解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33961184/