On this page
  1. Box Model & Formatting Contexts
  2. Contents
  3. Box Edges & Margin Collapsing
  4. Block Formatting Contexts (BFC)

Box Model & Formatting Contexts

Prev: Cascade, Specificity & Inheritance | Up: tutorials | Next: Modern Layout: Flexbox & Grid
Rel: Box Model & Sizing, Positioning & Stacking
Ref: MDN Web Docs — Block Formatting Context
Tags: #public #web #css #tutorials #box-model


Contents


Box Edges & Margin Collapsing

Every rendered element generates a box with four concentric areas: content -> padding -> border -> margin.

In normal block flow, adjacent vertical margins collapse into the larger of the two (rather than adding). Margins do not collapse inside Flex or Grid containers, or across padding/borders.


Block Formatting Contexts (BFC)

A Block Formatting Context is an isolated layout region that contains floats and prevents internal margins from collapsing out of its parent. Create a clean BFC without side effects using:

.section {
  display: flow-root;
}

Linked from

Related notes