After navigation bars, flex layouts power toolbars, card rows, and split panes. Think in main axis and cross axis terms.
Common recipes
- Horizontal row:
display: flex; gap: 1rem; - Centered cluster:
justify-content: center; align-items: center; - Push footer down: column flex on
bodywithmain { flex: 1; }
Item properties
flex: 1— grow to fill free space.flex-shrink: 0— prevent squashing icons.
Practice
- Change
flex-directiontocolumnon.row. - Set one child to
flex: 2and others toflex: 1.
More flex lessons: CSS Flexbox topic.
Important interview questions and answers
- Q: What is the flex main axis?
A: The direction flex items flow—row (horizontal) or column (vertical) depending on `flex-direction`. - Q: `align-items` vs `justify-content`?
A: `justify-content` aligns on the main axis; `align-items` on the cross axis. - Q: When does flex fail?
A: Complex two-dimensional page layouts are often clearer with Grid.