liveBook · Manning

Offset property

As explained in Web Design Playground, Second Edition

CSS offset properties specify an element's distance from the corresponding edges of its positioning context.

CSS offset properties tell a positioned element how far to move from an edge of its positioning context. The four familiar controls are top, right, bottom, and left. section 8.7

Use offset properties with the CSS position property:

  • static ignores offsets; relative shifts an element from its normal spot while keeping its space in the page flow. section 8.7
  • absolute places an element within the nearest nonstatic ancestor, while fixed places it within the browser viewport; both remove it from normal flow. section 8.7
  • sticky begins as relative positioning, then sticks when scrolling reaches the specified offset threshold. section 8.11
  • Set offsets with px, em, rem, vw, vh, percentages, or auto. section 8.7

A navigation row that sticks

A navigation element can scroll normally until its top edge reaches 5 pixels from the viewport’s top, where it stays temporarily. When its parent boundary catches up, it becomes unstuck and scrolls away. section 8.11

.nav-links {
    position: sticky;
    top: 5px;
}

This small rule pairs sticky positioning with a top offset, creating the navigation behavior described above. section 8.11

How Web Design Playground, Second Edition covers it

How deep it goes
Defines four offsets, accepted units, and interactions with position modes, while deferring detailed mode explanations.
Examples
Demonstrates sticky navigation at top: 5px and sticky headings at top: 0.
What it assumes
Assumes basic CSS measurement units and introduces how positioning modes change offset behavior.
What you can do after
Apply offset values with position to place, shift, fix, or stick elements in CSS layouts.
How it connects
Connects offset properties to the position property, sticky positioning, containing blocks, document flow, and z-index.

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.