Re:Help us invent CSS Grid Level 3, a.k.a. "Masonry" layout
by reactordev on Tuesday April 23, 2024 @04:57PM
(#40137170)
Does it require a ::last-child hack to get working? I’m a fan of grids when it comes to heavy writing content like I mentioned but I still don’t think it should all be packed in the spec.
[ Parent
| on HN ]
Re:Help us invent CSS Grid Level 3, a.k.a. "Masonry" layout
by rhdunn on Wednesday April 24, 2024 @03:24AM
(#40141620)
No, just:
main.books {
display: grid;
grid-template-columns: repeat(auto-fill, 180px);
grid-gap: 1rem;
justify-content: space-between;
}
That will make the child items 180px wide, repeat as many children in a row as needed to fill the width with a gap of atleast 1rem extended so that the items are justified to the left and right and are spread evenly. The last row has however many children are left with those children positioned to match the rows above.
Re:Help us invent CSS Grid Level 3, a.k.a. "Masonry" layout
by reactordev on Wednesday April 24, 2024 @10:53AM
(#40145085)
I meant without CSS Grid.
Re:Help us invent CSS Grid Level 3, a.k.a. "Masonry" layout
by rhdunn on Wednesday April 24, 2024 @02:59PM
(#40148167)
Ah, ok. I wasn't able to get the last row working right with flex, but didn't experiment too much as the CSS grid approach worked. You could look through the other answers in that StackOverflow question.
Re:Help us invent CSS Grid Level 3, a.k.a. "Masonry" layout
by reactordev on Wednesday April 24, 2024 @03:15PM
(#40148358)
I have. It’s a mix of people saying it’s can only be done with CSS grid semantics and then a few who prove them wrong with flex box. Reinforcing my above question about “why not :after? :last-child? And flex it into shape?”
But I get it. Grids are easy to grok and grid.css is for the birds. Bake it in. Bloat the spec. And allow pixel perfect precision with one (or two) less div.