liveBook · Manning

Margin property

As explained in Build a Website with ChatGPT

A margin property specifies the outer space surrounding an element's border.

The margin property controls the whitespace outside an element’s border. It creates space between neighboring elements and between an element and the browser viewport. Positive values separate elements; negative values can make them overlap. section 4.2.3

Set margins on one or more sides:

  • Supply one value when every side should have the same margin. section 4.2.3

Give a footer breathing room

A footer can use different spacing on each side: footer { margin-top: 24px; margin-right: 40px; margin-bottom: 32px; margin-left: 48px; }. The shorthand version is footer { margin: 24px 40px 32px 48px; }. To adjust the page, increase the margin when content feels crowded or decrease it when items feel disconnected; keep the px unit in place. section 4.4

element {
    margin-top: top-value;
    margin-right: right-value;
    margin-bottom: bottom-value;
    margin-left: left-value;
}

Browse the side-by-side margin declarations to see how each side is controlled. section 4.2.3

How Build a Website with ChatGPT covers it

How deep it goes
Defines side-specific and shorthand declarations, including positive spacing and negative overlap.
Examples
Uses a footer with four distinct margins and an equivalent shorthand declaration.
What it assumes
Builds from the element box and introduces margin alongside padding and borders.
What you can do after
Apply spacing through CSS side properties, shorthand declarations, and adjusted pixel values.
How it connects
Connects the CSS box model with padding, borders, spacing, and page customization.

Also explained in

Compare how 5 books explain margin property →

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.