Comment by rckt
3 days ago
I never found it comfortable to work with grids. The syntax and layout just feel off. Flexbox is a much more flexible and easy thing to work with.
3 days ago
I never found it comfortable to work with grids. The syntax and layout just feel off. Flexbox is a much more flexible and easy thing to work with.
There's plenty of overlap, but they solve different problems: flexbox when the content should control element sizing/fit, grid when the container should control element sizing/fit.
Another way to think about it: flexbox is for alignment of boxes in one dimension: horizontally or vertically.
CSS Grid is for two dimensional layout of rows and columns.
Back in the day, developers wanted page layout instead of the hacks on top of hacks with table-based layouts, floats and positioning to create layouts.
We’ve had CSS Grid designed for page layout on the web, in all browsers since 2017; as of 2022, only 12% of the top 1 million websites used CSS Grid, which to me is ridiculously low.
I use flexbox for grid purposes, simply because the syntax is straightforward and easy to read. Yeah, it’s one dimension, but if you nest it, it becomes two with no issues.
2 replies →
I think the grid syntax is really off-putting - it’s one of the few places of “typical” CSS I tend to avoid unless something really calls for it. In my experience, it feels like the people most familiar with grid display, the syntax, and using it, are more on the design side than the programming side - most of my frontend peers who use it tend to misuse it when flex would work fine and be less rigid for their goals
But flex grow and align stretch exist, which moves control back to the parent...
A grid really feels like a list flexes to me too, functionally.
I agree. I occasionally turn to them to see if they work in a new setting, but find they never expose the features of a grid I would find useful. Everything must be manually placed, rather than allowing content to intelligently snap to multiple axes. Possibly I never have grasped some fundamental concept, possibly they are not suited to the sorts of layouts I usually work on. But more and more I feel they are designed to fulfil some purpose orthogonal to what I would need them to do.
I also find it much simpler to make responsive designs with flexbox than with grid.