Skip to main content

Box Model & Positioning Elements

The Box Model

image

The Box Model with box-sizing: border-box;

image

  1. Positioning theory
  2. More about the "position" property
  3. The z-index
  4. The Stacking Context
  5. Mastering margin collapsing

Deep Dive on Margin Collapsing

Margin Collapsing

In this case, the first element might have a margin of 10px (on all sides let's say) and the second one has 5px (or 20px - the values don't matter). CSS will collapse the margins and only add the bigger one between the elements. So if we got margins of 10px and 5px , a 10px margin would be added between the elements

Shorthand Properties

image

"display: none" vs "visibility: hidden"

info

display: none;: This value removes the element to which you apply it from the document flow. This means that the element is not visible and it also doesn't block its position. Other elements can (and will) take its place instead. It's still part of the DOM though, you can still access it via JavaScript for example.

Box Types: inline, block-level and inline-block

image

Positioning Schemes: Normal flow, Absolute positioning and Floats

image

  1. When Using !important is The Right Choice
  2. The :not() pseudo class

Float and Clear fix

  1. Working With CSS Float And Clear Properties
  2. More on float - MDN
tip
  • In CSS, floating elements automatically have a display: block; applied to them. Floating elements behave similarly to blocks, and you can set a specific height and width.
  • When floating block-level elements, they wrap around their content instead of taking up all available width. This means they behave more like inline-block elements, even though their display property remains as block in CSS.