Module 15: Page Layouts

Lesson 3 of 5 · 15–25 minutes

Flexbox for real layouts

🏠The everyday picture

Three price cards in a row on a wide table, which stack one above the other when the table is narrow. They share the space fairly.

📘What it really is

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }

100vh means the full height of the screen; main grows to push the footer down.

🖱️Try it

On your home page, add a <section class="cards"> with three <article>s (for example, three things you want to build). Style .cards with display: flex; flex-wrap: wrap; gap: 1rem; and each article with flex: 1 1 250px, padding, a border and rounded corners. Make your browser window narrow and wide, and watch them wrap.

✅Quick check

Three cards each have flex: 1. What happens to the width?

Show the answer

They share the available width equally.

Your footer floats in the middle of a short page. What's a fix?

Show the answer

Make body a column flex container with min-height: 100vh and give main flex: 1.

← PreviousFlexbox basics
ProLearners Assist