Naar hoofdinhoud
← 🎨 CSS as a design systemΒ·Module B3 Β· Les 11
OpdrachtBuild a label + input grid. .form: display: grid, grid-template-columns: max-content 1fr, gap: 8px 16px. Inside: 3 pairs of <label> + <input>. Labels are 'Email', 'Password', 'Confirm password'.

Intrinsieke maatvoering: min-inhoud, max-inhoud, automatisch

75 XP6 min
Theorie

Sizes based on content, not pixels

CSS Grid offers three "intrinsic" track sizes:

grid-template-columns: min-content 1fr max-content;
  • `min-content` β€” the smallest size where the content doesn't overflow. For text: the width of the LONGEST WORD.
  • `max-content` β€” the size where the content uses no line breaks. For text: the width of the FULL UN-WRAPPED line.
  • `auto` β€” the browser picks something reasonable based on content + available space.

When each is useful

/* Label column sized to its widest label, value column gets the rest */
.form-grid { grid-template-columns: max-content 1fr; }

/* "As narrow as possible" sidebar */
.nav { grid-template-columns: min-content 1fr; }

For form-style layouts, max-content 1fr is the perfect "label + input" recipe.

fit-content() β€” clamp intrinsic sizing

grid-template-columns: fit-content(200px) 1fr;

The first column is sized to its content, but capped at 200px. Above 200px it wraps. Useful for "as wide as content, but not absurd."

πŸ”’

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.