Why use flex and not grid?
I'm learning how to work with display: grid at the moment and I'm pretty close to finish it, and from what I have learned so far grid can basically do everything flex can do, but also can do a bunch of other useful stuff, so I'm wondering, why would I ever prefer flex over grid? Is there anything I have missed?
8/9/2020 12:04:52 PMKarak10
3 AnswersNew Answer
- Flex has more support. IE supports it. - Flex is easier to use for one-dimensional components. - Flex is easier to understand by beginners - Flex gives you more flexibility on the position of individual items. This are just possible reasons to use flex. There are many more reasons to use grid. I don't prefer one over the other. I use both when I deem fit.
KINGDX Before flex and grid, we created grids and flexible boxes with css hacks and antipatterns. Similarly, flex can be used to create 2D-ish layouts but it is not so easy, neither is it efficient. For full page layouts or other grid-like layouts it is better to use grid unless you are worried about support.
I honestly never really used CSS grids so I can't offer a good comparison between the two, but nowadays I primarily use flex for its ability to easily center things vertically on top of doing all the other alignments. I have never came across a case that flexbox doesn't have a solution to tbh.