Module 15: Page Layouts

Lesson 1 of 5 · 15–25 minutes

The box model

🏠The everyday picture

A framed photo on a wall: the photo, the white mount around it, the frame, and the empty wall space before the next frame. Every element on a web page is a box built the same way.

📘What it really is

*, *::before, *::after {
  box-sizing: border-box;
}

Now width includes padding and border, so 300px means 300px.

🖱️Try it

Add the box-sizing rule to the top of style.css. Then Inspect any element: at the bottom of the Styles panel (or in the Computed tab) is a diagram of its content, padding, border and margin. Hover each layer to see it highlighted on the page.

✅Quick check

A box is width: 200px with 10px padding and a 1px border, without border-box. How wide is it?

Show the answer

222px: 200 + 10 + 10 + 1 + 1.

Why can't you set a width on a link (<a>) without changing anything else?

Show the answer

Links are inline elements, which ignore width. Make it display: inline-block or block.

← BackModule 15
ProLearners Assist