isn't all of this solved more easily via flexbox?
isn't all of this solved more easily via flexbox?
This becomes more complicated when the number of divs is dynamic as flex determines position based on siblings. With grid you already have defined the “layout”, and you are just placing the div into the correct position.
Grid does that in both axis too. So although you may be able to kind of replicate the 1d version with flex, it becomes much harder to align in 2D.
I wrote an article about this: https://cssprinciples.com/3/grid/
.flex {
display: flex;
gap: 8px;
}Grid -> 2-dimensional layouts
That being said, I use Flexbox for pretty much everything.
Flexbox -> the children define the size Grid -> the parent is in control
Flexbox -> Content first, Layout second.
Grid -> Layout first, Content second.
I've never been in a situation where nesting grids makes sense. Nesting flexbox obviates the need for grid in most cases.