News for hackers. Stuff that matters.
Re:CSS Grid Areas by jdthedisciple on Friday August 16, 2024 @03:04AM (#41263867)
Probably a cliché question at this point but

isn't all of this solved more easily via flexbox?

Re:CSS Grid Areas by rasso on Friday August 16, 2024 @03:08AM (#41263889)
Kevin Powell has a few great videos on YT comparing flexbox to grid. Grid can be very powerful if you want overlapping grid areas. Something that was previously only possible using absolute positioning. Also, auto-fit and auto-fill
Re:CSS Grid Areas by arcanemachiner on Friday August 16, 2024 @03:06AM (#41263873)
Flexbox -> 1-dimensional layouts

Grid -> 2-dimensional layouts

That being said, I use Flexbox for pretty much everything.

Re:CSS Grid Areas by rasso on Friday August 16, 2024 @03:09AM (#41263896)
That‘s a very popular over-simplification. A better one would be:

Flexbox -> the children define the size Grid -> the parent is in control

Re:CSS Grid Areas by reactor on Friday August 16, 2024 @07:30AM (#41265348)
For me its:

Flexbox -> Content first, Layout second.

Grid -> Layout first, Content second.

Re:CSS Grid Areas by kevsim on Friday August 16, 2024 @03:15AM (#41263931)
The main reason I tend to reach for grid is responsiveness. Makes it way easier to change the layout at different screen sizes.
Re:CSS Grid Areas by emadda on Friday August 16, 2024 @07:08AM (#41265226)
One thing flex cannot do well is white space: how do you leave a gap of content without spacer divs?

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/

Re:CSS Grid Areas by jdthedisciple on Saturday August 17, 2024 @05:07AM (#41272951)
gap works with flexbox I believe

    .flex {
      display: flex;
      gap: 8px;
    }
Re:CSS Grid Areas by emadda on Saturday August 17, 2024 @10:24AM (#41274820)
I mean gaps of white space that are part of the design and could possibly host content for different app states (not uniformly distributed between flex items).
Re:CSS Grid Areas by bob1029 on Friday August 16, 2024 @08:31AM (#41265789)
I typically look at grid as the outermost container. It is very good at dealing with coarse layout concerns because you can constrain on both dimensions and define a layout per media query (or whatever).

I've never been in a situation where nesting grids makes sense. Nesting flexbox obviates the need for grid in most cases.

Re:CSS Grid Areas by nsonha on Friday August 16, 2024 @12:04PM (#41267593)
not at all, the wet dream of css is to be able to layout just with css and only semantic markup, to which flexbox falls short sometimes because you need to add non-semantic elements (columns and rows).