Module 3 · Responsive layout17 min lesson

Build a layout that adapts

Use CSS Grid, minmax(), and gap to make a resource layout respond to available space, then recover the exact saved practice after sign-in.

Start with the idea

01

Layout describes a relationship, not a screen size.

A responsive layout keeps its meaning as space changes. Instead of choosing a fixed number of columns, describe the smallest useful card and let the browser decide how many fit.

.resource-grid {
  display: grid;
}
.resource-gridevery direct resource card

02

Give every column a safe minimum and a flexible maximum.

minmax(14rem, 1fr) protects readability at the narrow end and shares spare space at the wide end. 1fr means one fraction of the available row.

.resource-grid {
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
}
Why auto-fit matters

The browser adds or removes tracks as the container changes. The layout responds to its actual space without a device list.

03

Use gap for the relationship between cards.

A grid gap belongs to the container, so every row and column uses one spacing rule. min-width: 0 lets long card content shrink instead of forcing the track wider.

.resource-grid {
  gap: 1rem;
}

.resource-card {
  min-width: 0;
}

Five-minute practice

Make three cards adapt without a breakpoint.

Finish the saved CSS below. Resize the page and watch the same rule move from one column to several without hiding content.

Saved practice · Responsive CSS Grid

Make one resource grid adapt.

Finish the track rule, add one shared gap, and keep long card content inside its column. The preview updates as you type.

Expected outcomeThree resource cards that move from one column to several and pass all four layout checks.
Not saved2/4practice checks
layout.cssLocal draft
Live previewNetwork blocked

Practice checks

Four layout choices, checked on the server.

2/4 passing
Make the resource list a grid

Keep display: grid inside .resource-grid.

Let columns respond to available space

Use repeat() with auto-fit or auto-fill and minmax() in grid-template-columns.

Separate cards without individual margins

Add a non-zero gap to .resource-grid.

Allow card content to shrink inside the track

Keep min-width: 0 inside .resource-card.

Starter CSS is ready. Save when the cards adapt cleanly.

Active recall

Check your mental model.

75% to complete

Answer from memory. You can choose all four answers before deciding whether to check them.

01What does display: grid change on .resource-grid?
02What does minmax(14rem, 1fr) describe?
03Why combine repeat() with auto-fit?
04Why is gap a strong choice for space between grid cards?

Choose answers from memory, then check your work.