Flexbox
6 min read Quiz at the end
Flexbox arranges items in a row or column. Set display: flex on the container. justify-content aligns along the main axis. align-items aligns on the cross axis. gap adds space between all flex items easily.
Flexbox .container {
display: flex;
flex-direction: row; /* row | column */
justify-content: center; /* main axis */
align-items: center; /* cross axis */
gap: 16px;
flex-wrap: wrap;
}
.item {
flex: 1; /* grow and shrink equally */
flex: 0 0 200px; /* fixed 200px, no grow/shrink */
}
/* Center anything */
.center {
display: flex;
justify-content: center;
align-items: center;
}
Topic Quiz · 5 questions
Test your understanding before moving on
1. justify-content aligns items on:
A. Cross axis
B. Main axis
C. Both axes
D. Z-axis
💡 justify-content aligns items along the main axis (row direction by default).
2. align-items aligns items on:
A. Main axis
B. Cross axis
C. Both axes
D. Z-axis
💡 align-items aligns items on the cross axis (perpendicular to main axis).
3. How do you centre both horizontally and vertically?
A. text-align: center
B. display: flex; justify-content: center; align-items: center
C. margin: auto
D. position: center
💡 Flexbox centering: display:flex; justify-content:center; align-items:center.
4. flex-wrap: wrap does what?
A. Removes flex
B. Forces items onto next line when they don't fit
C. Adds borders
D. Makes items equal width
💡 flex-wrap: wrap lets items flow to a new line instead of shrinking.
5. flex: 1 means:
A. Fixed size 1px
B. Item grows and shrinks equally, takes available space
C. Item is hidden
D. Item is 1 column wide
💡 flex: 1 = flex-grow: 1, flex-shrink: 1, flex-basis: 0% — equal flexible sizing.
Submit answers