Flexbox solves one-dimensional layout problems: alignment and distribution along a row or column.
When to choose flexbox
- Navigation bars and toolbars.
- Card header/footer alignment.
- Button groups and responsive wrapping rows.
Important interview questions and answers
- Q: Flexbox vs Grid in one sentence?
A: Flexbox is one-dimensional; Grid handles two-dimensional track layouts. - Q: Why use gap in flex?
A: Cleaner spacing without child-margin hacks. - Q: Common flex bug?
A: Content overflow due to missing min-width handling.
Challenge
Center a card
- Use flex parent with
justify-content:centerandalign-items:center.
Done when: card is centered in the preview area.