Web DesignResponsive & accessibleLesson 10 / 69

Media queries & fluid units

Fill-gap25 min

Media queries & fluid units

A responsive page adapts to the viewport. Two tools do most of the work:

/* 1fr splits available space fluidly */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* A media query overrides at narrow widths */
@media (max-width: 600px) {
  .page { grid-template-columns: 1fr; }
}

Prefer fluid sizing (%, fr, rem, clamp()) over fixed pixels so the page breathes, and use media queries at the breakpoints where the layout actually breaks — found by resizing, not guessed.

Exercise

Make a card grid that shows 3 across on desktop, 2 on a tablet, 1 on mobile — using auto-fill plus one media query.