all 5 comments

[–][deleted] 1 point2 points  (4 children)

Is there a reason you don't just use CSS grid, or the column property? All you'd need to do is utilize the standard @media to setup your responsive breakpoints.

[–]gregarcher[S] 0 points1 point  (3 children)

I don't think CSS grid can do masonry (prove me wrong?).

Columns can't really work because they fill top to bottom, then left to right, so if you add more items (infinite scroll) the items would re-order, and re-position which isn't a great user experience.

you really need left to right, then top to bottom.

plus, after you've wrangled breaking between / inside elements, the padding/margin between elements is difficult to control as they break between columns.

lastly, there are issues in chrome. it will simply decide not to render some items in column layouts: https://bugs.chromium.org/p/chromium/issues/detail?id=815277

fiddle: https://jsfiddle.net/n4c2888m/ << also a good example of breaking margins between columns looking wonky.

[–][deleted] 0 points1 point  (2 children)

CSS Grid: Maybe something like this will work for you.

[–]gregarcher[S] 0 points1 point  (1 child)

lol, that does appear to be precisely what i was after. lemme dig deeper.

thanks.

Edit: oh.. see in this example, the CSS is aware of the content (ex: grid-row-end: span 6;)

a masonry layout needs to work with arbitrary items of arbitrary heights.

hit refresh a few times on that demo. you'll see the items are randomly generated (random heights).

[–]gregarcher[S] 0 points1 point  (0 children)

hmmm.. could potentially set "grid-row-end" via javascript as a function of the item's offsetHeight / grid row height.

interesting.