2015-11-27 364 views
4

我想问一些关于响应式图库。响应式图片库解决方案

这是我想要做的一个例子。所以,如您所见,图像的大小不固定。它只是保存比例的缩略图。

我不确定它是如何工作的。我应该如何让我的回应?

应该怎么做?如果有一些现成的解决方案,请告诉我。

谢谢。

+2

尝试使用masonary图书馆http://masonry.desandro.com/ – kmike

回答

1

正如其他人说你可以用砖石

演示: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; 
} 
+0

感谢您的回答。但它不是我所需要的:)请看图片。正如你看到的图像之间的差距是相同的,它仍然是完美的容器。 – Tigran