liveBook · Manning

Sticky positioning

As explained in Web Design Playground, Second Edition

Sticky positioning is a CSS positioning mode in which an element behaves relatively until a specified offset threshold is reached and then behaves fixed within its containing block.

Sticky positioning blends relative and fixed behavior: an element scrolls normally until it reaches an offset threshold, then stays in place within its containing block. section 8.11

As the page scrolls, sticky positioning behaves like this:

  • The element begins in its normal position and moves with the page. section 8.11
  • A top, right, bottom, or left offset sets the point where it sticks. section 8.11
  • When the parent container reaches the stuck element, it becomes unstuck and continues scrolling with the parent. section 8.11

A navigation bar that sticks

nav { position: sticky; top: 0; z-index: 10; } This lets the navigation scroll normally until it reaches the top of the viewport, where it remains visible without forcing the page header to stay fixed. section 15.8

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

Use this small rule as a starting pattern for making navigation links stick five pixels from the top of the viewport. section 8.11

How Web Design Playground, Second Edition covers it

How deep it goes
Defines relative-to-fixed transitions, offset thresholds, and parent-boundary release, then demonstrates navigation CSS.
Examples
Uses sticky navigation links at 5px from the top and a photo-gallery navigation bar fixed at the viewport top.
What it assumes
Distinguishes sticky from static, relative, absolute, and fixed positioning while introducing the position property’s options.
What you can do after
Apply it via CSS to create navigation that sticks at a viewport edge while remaining bounded by its parent.
How it connects
Connects CSS positioning with offset properties, containing blocks, scrolling, 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.