liveBook · Manning

CSS box model

As explained in Build a Website with ChatGPT

The CSS layout model in which each element is represented by content, padding, border, and margin regions.

The CSS box model describes every element as an invisible box with four regions: content, padding, border, and margin. Content holds text or an image; padding adds space around it; the border surrounds the padding; and the margin adds space outside the border. section 4.2.3 section 4.5

Use these CSS properties to adjust each region:

  • Set padding to give content room to breathe. One value applies to all four sides, while four values set top, right, bottom, and left independently. section 4.2.3
  • Set a border to draw a line around the padding, such as 1px solid black. section 4.2.3
  • Set margin to add whitespace outside the border and separate the element from nearby elements. section 4.2.3 section 4.5

Give a header room

A CSS rule such as `header { padding: 16px 24px 12px 20px; }` adds different amounts of space to the header’s four sides. For equal spacing, use `body { padding: 16px; }`.

How Build a Website with ChatGPT covers it

How deep it goes
Defines four regions and demonstrates padding, border, and margin syntax, without developing advanced layout behavior.
Examples
Uses header, footer, nav, body, pixel measurements, padding shorthand, and a solid black border.
What it assumes
Assumes familiarity with page elements and CSS declarations while explaining the box regions from the beginning.
What you can do after
Apply padding, borders, and margins to page elements through CSS declarations or explicit generation prompts.
How it connects
Connects content, padding, borders, margins, HTML elements, page structure, and CSS prompts.

Also explained in

Compare how 6 books explain CSS box model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Website with ChatGPT. The section links point to the parts of the book it draws on.