Hacker News new | past | comments | ask | show | jobs | submit login

Reposting as a top comment for more visibility:

I have a website with my photos, which doesn’t use any JS for layout. When I was making it, I considered using JS masonry libraries, but I wasn’t satisfied with the results. Proper masonry layouts which fill all available space in practice actually crop some images. Leaving space around photos is required when you don’t want cropping and want to preserve aspect ratio. The only way not to do that is to have infinite scroll, which I guess is what corporate addiction machines want, but that’s not what I want on my own website. Here is what I did:

https://yakubin.com/photography/albumless/

https://yakubin.com/photography/album/kenya-2023/

I used display:inline-block to achieve this result, effectively treating photos as text that needs to reflow into new lines. I’m very satisfied with the result and prefer it over what the masonry libraries do.




You could probably have done this layout in a couple lines of CSS with a row-oriented flexbox that wraps and is center-aligned. That would be the more standard way to do it too.


I don't use JS for masonry layout. I have a fallback from the current masonry CSS solution to a supported CSS solution.

The problem is ordering. The current CSS-only solutions work fine as long as the order is not important. (though you will still end up with weirdness at the bottoms of the columns IIRC)


Flexbox was designed for these kinds of layouts, so that would also be an option here.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: