Flexbox is amazing and powerful, but can feel so broken when you don't know the pitfalls and gotchas to watch out for. The emotion train of using flexbox typically goes like this:
That's how it was for me as well. I got so frustrated I decided to dive super deep and master the flexbox beast. Since then I've helped over 10,000 devs master flexbox through answering questions and building a full on Flexbox Zombies Mastery Game. From this experience I've seen patterns of what things trip people up the most. Here are the most common pitfalls and how to avoid them.
flex
shorthand changes flexbox defaultsThe most common pitfall is what happens when you use the flex
shorthand. See The Flex Shorthand Doesn't Play Nice
order
property is zero-basedUsing order
makes items jump around in unexpected ways until you get how it actually works. See How Flexbox Order Works
flex-basis
is a curious beastThe flex-basis
property is fundamental to flexbox, and it has some important/interesting interactions with other properties like width
, min-width
, and max-width
. See The Difference Between Width and Flex Basis
flex-wrap
flips your world upside downAs soon as you run out of space for all your flex items in a single line, you're going to need flex-wrap
. This new property has a couple of gotchas, changes how items grow and shrink, and there's one value you'll want to avoid entirely! See Wrap Your Brain Around Flex-Wrap
Flexbox is incredibly powerful. But it's also crazy hard to master. So we all end up depending on a cheat sheet and guessing in the dev tools. Enough of that! Time to master it once and for all, in a way that actually sticks, so you can build any layout you can imagine with flexbox.Master Flexbox