如何动态创建图像的拼贴画(无间隙的网格),其中图像具有不同的高度?
我想显示一页缩略图。缩略图是用户上传的艺术作品图像。每个图像都有一个受限的宽度,但没有一个受限的高度,这是为了显示完整的图像而不进行任何裁剪。
我希望这些图像能够相互对接,中间没有间隙。列数不固定:如果我扩展或调整页面大小,图像应流入正确的列数。
float:left
几乎就是我想要的。除非页面中有高图像,否则我会看到这种有间隙的外观:
如何消除间隙?
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:
How do I eliminate the gaps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定你需要多么优雅的 CSS,但仍然是一个不错的选择。您可以使用 masonry.js 来帮助实现这一点。
http://css-tricks.com/seamless-responsive-photo-grid/
Not sure how graceful you need your CSS, but a good option none the less. You could use masonry.js to help that.
http://css-tricks.com/seamless-responsive-photo-grid/
如果你只想在 css 中执行此操作,则必须为每个列创建 div,并使这些列浮动(但它会打乱图像的顺序)。
或者,您可以使用 jquery 插件,例如这个。
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).
Alternatively, you can use jquery plugin like this one.