News for hackers. Stuff that matters.
Re:CSS grid garden by revskill on Monday December 24, 2018 @02:07PM (#18753694)
Flex seems more flexible to me than CSS Grid.
Re:CSS grid garden by fro0116 on Monday December 24, 2018 @10:43PM (#18755762)
My only major pain point working with flexbox have been gutters. With flexbox, implementing gutters often involves some kind of hack involving negative margins, which is both inelegant and can sometime result in strange layout issues in my expereince.

For instance, if you want to render a dynamic list of items that wraps if the number of items don't fit in 1 row using flexbox, and want to add equal vertical spacing to each row _only when the list wraps_ (i.e. without introducing any extra spacing on the first row), you'd need to add a margin-top to every item and then add a negative margin-top to the flex container to counteract that extra margin.

I originally found out about this trick in this StackOverflow question: https://stackoverflow.com/a/30891910. I'd love to be enlightened if anyone know of a better way of implementing this using flexbox.

Similarly, adding gutters for horizontal spacing between columns involves adding 1/2 the gutter width as margins to each item on both sides, and then setting negative margins of 1/2 the gutter width on both sides of the container.

With grid, we can simply set the row-gap and column-gap properties on the grid container without any additional ceremony.

Re:CSS grid garden by reaperducer on Monday December 24, 2018 @03:19PM (#18754072)
Flex seems more flexible to me than CSS Grid

It's not an either/or proposition.

I sometimes use both at the same time, depending on the project. Usually it's Grid for the big picture container layout stuff, and then Flexbox for laying out each individual portion.

I'll be happy when another 15% of my visitors upgrade to better browsers so I can use grid on my biggest project. Right now Flexbox fails with orphan elements, even when using margin: auto;, but this would be a perfect place to use Grid.

Re:CSS grid garden by bgorman on Monday December 24, 2018 @02:54PM (#18753934)
They are complementary technologies. CSS Grid really shines for doing the "full page layout" portion of websites. One really useful feature of CSS grid is that it composes really well with media queries, so you can create responsive websites really easily by just defining different grid area layouts for various screen sizes.
Re:CSS grid garden by tgroutars on Monday December 24, 2018 @02:38PM (#18753854)
They actually made another game to learn flexbox https://flexboxfroggy.com/
Re:CSS grid garden by maximp on Monday December 24, 2018 @02:40PM (#18753863)
This is how I've learned enough flexbox to get by, and it was a total blast
Re:CSS grid garden by creyes on Monday December 24, 2018 @02:20PM (#18753762)
A combination of both is really ideal. CSS Grid seems great for full screen things and FlexBox is really great at laying out small components.
Re:CSS grid garden by aldoushuxley001 on Monday December 24, 2018 @02:22PM (#18753771)
Flex has better browser support though, so I still like to stick to Flex instead of Grid.
Re:CSS grid garden by devxpy on Monday December 24, 2018 @03:02PM (#18753972)
Is it just me or does everyone just eventually resorts to "trying everything until it works" with CSS layout?

> Flex seems more flexible to me than CSS Grid.

Any day :)

Re:CSS grid garden by adrianhel on Monday December 24, 2018 @08:00PM (#18755197)
My first advice to anyone regarding CSS: Don't just slap on more rules to get things working. Gain an intuition and you'll be so much happier and produce much better layouts.

But yes, I am also under that impression.

Re:CSS grid garden by fiddlerwoaroof on Monday December 24, 2018 @04:23PM (#18754332)
Honestly, my experience with both flex and grid is that they are 80% solutions and the easiest ways to get the other 20% is to rewrite everything using floats and `display: block`
Re:CSS grid garden by ben_jones on Monday December 24, 2018 @02:34PM (#18753839)
Agreed, since learning flexbox I haven't touched css grid albeit I've only done front-end for small internal tools and hobby projects recently.