Menu

How to Learn CSS Flexbox and Grid (and Stop Guessing Which One to Use)
📰

How to Learn CSS Flexbox and Grid (and Stop Guessing Which One to Use)

DEV Community: beginners·Spartan Rich·15 days ago
#cXLBhcBK
#devtobeginners#devto#dev#grid#flex
Reading 0:00
15s threshold

For about two years my approach to CSS layout was trial and error. I'd type display: flex , add justify-content: center , watch nothing happen, swap it for align-items: center , and keep toggling properties in DevTools until the box landed roughly where I wanted. It worked, sort of. I just couldn't have told you why.

What fixed it wasn't another cheat sheet. It was learning a few ideas properly, in the right order, and then reviewing them until they stopped leaking out of my head. Here's the order I'd follow if I were starting again.

Learn the one idea that explains Flexbox

Flexbox has a main axis and a cross axis. That's most of it.

flex-direction sets the main axis. By default it's row , so the main axis runs left to right. justify-content moves items along the main axis.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.