Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I dynamically create a collage (grid with no gaps) of images, where images have different heights?

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:

enter image description here

How do I eliminate the gaps?

like image 531
Homan Avatar asked Jun 30 '11 21:06

Homan


People also ask

How do you make sure an image gets smaller when its container gets smaller in the layout?

keep the width of the photo at 100% (thus equal to its container) and scale the height of the container to fit the photo. Basically, when the window becomes smaller, the width of the photo becomes smaller, and so does the height - pulling the tag, album, and rotate elements up.


1 Answers

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/

like image 199
onefastsnail Avatar answered Oct 27 '22 19:10

onefastsnail