liveBook · Manning

Position property

As explained in Web Design Playground, Second Edition

The CSS position property specifies the positioning scheme used to lay out an element.

The CSS position property chooses how an element is placed instead of simply letting it follow the browser’s default page flow. Pair it with top, right, bottom, or left offsets; use z-index when overlapping elements need layering. section 8.7 section 8.12

Choose the positioning scheme that matches the job:

  • static keeps the browser’s default positioning and ignores offset properties. section 8.7
  • relative moves an element from its usual spot while preserving its space in the page flow. section 8.7
  • absolute removes an element from page flow and positions it against the nearest nonstatic ancestor, or the viewport when none exists. section 8.9
  • fixed removes an element from page flow and positions it against the browser viewport. section 8.7
  • sticky behaves relatively until scrolling crosses an offset threshold, then remains stuck until its containing block reaches it. section 8.11
element {
    position: static|relative|absolute|fixed|sticky;
    top: measurement|percentage|auto;
    right: measurement|percentage|auto;
    bottom: measurement|percentage|auto;
    left: measurement|percentage|auto;
    z-index: integer|auto;
}

Use this compact rule shape as a reminder of the position values, offset properties, and z-index syntax. section 8.7

A navigation row that sticks

A navigation row can scroll normally until its top reaches 5 pixels from the viewport’s top edge, then stay visible: .nav-links { position: sticky; top: 5px; }. Unlike a permanent fixture, it becomes unstuck when its parent boundary reaches it. section 8.11

A tooltip with absolute positioning

Make a containing element relative, then place a nested tooltip absolutely. With top: 0 and left: 0, the tooltip sits at the containing element’s top-left corner rather than taking up normal page space. section 8.9

How Web Design Playground, Second Edition covers it

How deep it goes
Defines all five values and offsets, then works through absolute ancestors and sticky thresholds without detailing every mode equally.
Examples
Uses sticky navigation links and absolutely positioned tooltips, spans, and nested strong elements.
What it assumes
Builds from default page flow and CSS measurements while introducing positioning schemes, offsets, ancestors, and stacking contexts.
What you can do after
Apply it via CSS to place elements, create sticky navigation, build tooltips, and layer overlaps with z-index.
How it connects
Connects default page flow, CSS offset properties, containing ancestors, z-index, and stacking contexts.

Also explained in

Compare how 2 books explain position property →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.