TutreNews Learn

Layout and responsive design

Display and positioning

Goal: Choose block, inline and inline-block and place elements with position · 11 min

display decides how an element takes part in the page flow.

  • block (div, p, h1, section): starts on a new line and takes the full width; width, height, margins and padding all work.
  • inline (span, a, strong): flows within a line; **width and height are ignored** and vertical margins do not push lines apart.
  • inline-block: flows like text but accepts width, height and vertical margins.
  • none: removes the element completely (no space left). Compare visibility: hidden, which hides it but keeps its space.
  • flex and grid: modern layout containers (next lessons).

position takes elements out of or shifts them within the normal flow:

valuebehaviour
staticdefault; ignores top/left
relativestays in the flow, can be shifted with top/left; it is the anchor for absolute children
absoluteremoved from the flow, placed relative to the nearest positioned ancestor (not static)
fixedplaced relative to the viewport; stays when scrolling
stickynormal flow until a scroll threshold, then sticks (e.g. a header)
.card { position: relative; }
.card .badge { position: absolute; top: 8px; right: 8px; }

The badge sits 8px from the top-right corner of its card, because the card is the nearest positioned ancestor. Use positioning for small overlays; use Flexbox and Grid for page layouts.

Worked example: A badge on a card

  1. Make the card the positioning anchor: position: relative.
  2. Give the badge position: absolute and top/right offsets.
  3. The badge no longer takes space in the flow and overlaps the corner.
.card { position: relative; }
.badge {
  position: absolute;
  top: 8px;
  right: 8px;
}