If you look at masonry layouts, they accommodate the variation in image sizes by having a uneven bottom border.
Here, you’re doing a rotated masonry, so if all images are full-sized, and your row heights are even, then you’d have an uneven right border.
Basically that variablity has to go somewhere, and on top of that you need to contend with responsiveness and your total image count to achieve the full-rectangle gallery effect.
There are ways to make it perfectly rectangular though.
You can either-
- Dictate and control the exact aspect ratio and sequencing of the images, like in your image above, or
- Dictate display aspect ratios, and control the arrangement per line ( 2 landscape, 2 portrait / 1 landscape, 1 portrait / etc ) But you don’t necessarily show the whole image- just a centered crop using aspect ratio and object-fit cover.
This caveat breaks #1 as an option, so I’d probably go for #2.
Here you care about the presentation sequences ( landscape, portrait, repeating ), but since you’re doing an object-fit cover crop, it doesn’t actually matter what the image actually is.
It’s a hack… it’s reasonable to implement without some wacky size-sorting algorithms, and achieves the presentation goal above.
I’d probably randomize the list but force a fixed repeating arrangement of landscape, portrait, landscape, portrait.
You can control that variation by CSS using :nth-item
, and although some landscape images would be cropped to portrait, etc, you’d have a nice neat looking layout, with perfect edges ( if you have enough images to fill the space ).
A lightbox could show the full view.