如何动态创建图像的拼贴(没有间隙的网格),其中图像具有不同的高度?

2022-01-18 00:00:00 image grid css gaps-in-visuals css-float

我想显示一页缩略图.缩略图是用户上传的艺术品图像.每张图片都有一个限制的宽度,但没有限制的高度,这是为了显示完整的图像而不进行任何裁剪.

I want to display a page of thumbnails. The thumbnails are user uploaded artwork images. Each image has a constrained width, but not a constrained height, this is to show the full image without any cropping.

我希望图像相互对接,中间没有间隙.列数不固定:如果我扩展或调整页面大小,图像应该流入正确的列数.

I want the images to butt up against each other with no gaps in between. The number of columns is not fixed: If I expand or resize the page the images should flow into correct number of columns.

float:left

几乎是我想要的.除非页面中有高大的图像,否则我会看到这种间隙:

is ALMOST, what I want. Except when there are tall images in the page I get this gapped look:

如何消除差距?

推荐答案

如果您只想在 css 中执行此操作,您必须为每一列创建 div,并浮动这些列(但它会打乱图像的顺序).

If you want to do this in css only you have to create divs for every column, and float those columns (but it messes up order of images).

或者,您可以使用 this one 之类的 jquery 插件.

Alternatively, you can use jquery plugin like this one.

相关文章