Naar hoofdinhoud
← 🎨 CSS as a design systemΒ·Module B3 Β· Les 3
OpdrachtBuild a grid with columns 1fr 3fr 1fr (narrow, wide, narrow). .grid has display: grid, grid-template-columns: 1fr 3fr 1fr, gap: 12px. Three .cell divs.

De fr-eenheid: fractionele ruimte

75 XP6 min
Theorie

fr = a unit that means "share of available space"

grid-template-columns: 1fr 1fr;          /* two equal columns */
grid-template-columns: 1fr 2fr;          /* second column is 2x first */
grid-template-columns: 1fr 1fr 1fr 1fr;  /* four equal columns */
grid-template-columns: repeat(4, 1fr);   /* same β€” shorthand */

After fixed-pixel tracks reserve their space, fr units split what's left. So:

grid-template-columns: 200px 1fr 1fr;

With a 1000px container: 200px goes to col 1. The remaining 800px splits into two 400px columns.

fr beats % when you have gaps

Compare:

/* % math: each col is 50% β€” but gap is INSIDE the container, so children overflow */
grid-template-columns: 50% 50%;
gap: 16px;

/* fr math: 1fr accounts for the gap. Container width = col1 + gap + col2 */
grid-template-columns: 1fr 1fr;
gap: 16px;

With %, the math is wrong when gaps exist. With fr, it's correct. Use fr for grids.

Decimal fractions

grid-template-columns: 0.5fr 1fr 0.5fr;  /* narrow, wide, narrow */

Works. The shares are 0.5 + 1 + 0.5 = 2 total parts; the wide column gets half (1/2), each narrow gets a quarter.

πŸ”’

Registreer om te beginnen met coderen

Theorie is voor iedereen. De editor, live preview en check ontgrendelen met een 7-daagse gratis proefperiode β€” kaart vereist, opzegbaar.

Registreren β€” gratis proef β†’

De eerste 10 lessen in elke track zijn gratis. Geen kaart nodig.

← VorigeVolgende les β†’

EΓ©n Python- of web-tip per dag β€” per e-mail

Kort, met de hand geschreven, geen spam. Met één klik afmelden.