One-dimensional layout with Flexbox
Turn navigation and card actions into wrapping, well-aligned one-dimensional layouts.
- Difficulty
- beginner
- Time
- 40 minutes
- Last verified
- 9/21/2026
What you will build
Turn navigation and card actions into wrapping, well-aligned one-dimensional layouts.
Understand the idea first
Flexbox distributes items along one dimension.
Build it step by step
.site-nav {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.75rem 1.25rem;
}
.card-actions {
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}
.card-actions > :last-child {
margin-inline-start: auto;
}- Identify the main axis before writing CSS.
- Use flex and gap instead of scattered margins.
- Enable wrapping and narrow the viewport.
- Inspect the layout with the Flex overlay.
Read the important lines
- Flexbox distributes items along one dimension.
- Justify works on the main axis; align works on the cross axis.
- Auto inline margin pushes one item to the end.
Common mistakes and what to check
| Symptom | What to check |
|---|---|
| Items become too narrow | Allow wrapping or set an appropriate basis. |
| Alignment appears ineffective | Check the cross axis and available space. |
Practice without copying
Build a wrapping header with brand first and grouped links while preserving DOM focus order.
Check the answer after you try
Do not use order to scramble focus; there is no horizontal scroll at 320px.
Completion check
- I produced the required visible result
- I can explain the input, processing, and output
- I tested normal, edge, and failure cases