Course contentsLesson 3 of 6← Course overview
  1. 01A page is a conversation18 min
  2. 02Give your content structure24 min
  3. 03Make a layout that adapts32 min
  4. 04Make a button do something35 min
  5. 05Make forms easier to use28 min
  6. 06Keep a trail of your work36 min

Web development · Lesson 03

Make a layout that adapts

Edit lesson

Build a simple layout that remains readable on small and large screens.

32 minProgress saves on this device
In this lesson
  • Describe the difference between flex and grid
  • Use a responsive rule to adjust a layout

Helpful background: Basic HTML elements and CSS selectors.

Start with the content

A good layout gives content room to breathe and keeps the reading order clear. Decide what should sit beside what, then choose a layout tool that fits.

Flexbox for a row or column

Flexbox is useful when items need to line up in one direction. It can distribute space and wrap items as the available width changes.

Grid for two dimensions

CSS Grid is useful when you want to define rows and columns together. A small media query can switch a two-column layout into a single column on narrow screens.

One layout, two screen sizescss
.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

@media (max-width: 42rem) {
  .cards { grid-template-columns: 1fr; }
}
Knowledge check

Which CSS tool is designed to manage rows and columns together?

Try first; feedback appears after you check.
Apply it

Your turn

Plan a card section with two columns on a wide screen and one column on a phone. Which rule changes the layout?

Continue readingMDN: CSS layout

BUILT TOGETHER

Help make this explanation better.

Have a clearer explanation, a useful example, or a correction? Share it with the community.

Contributors

Be the first to add your name when you improve this lesson.

How to get credited
Previous lessonNext lesson