Skip to content

Position

Position utilities set how an element is placed in the flow. They do not move it; offsets live on the Inset page, and stacking order lives on the Z-index page.

Class position
position-static static
position-relative relative
position-absolute absolute
position-fixed fixed
position-sticky sticky

Compact aliases: static, relative, absolute, fixed, sticky.

<header class="position-sticky" style="top: 0">Sticky header</header>
<button class="relative">…<span class="absolute">Badge</span></button>

Responsive: position-md-absolute, position-lg-sticky, and so on.

These classes are in the separate responsive module: import nightcss/utilities/responsive after the base bundle, or use nightcss/full.

  • relative keeps the element in flow and becomes the containing block for absolutely positioned children.
  • absolute takes the element out of flow and positions it against the nearest positioned ancestor.
  • fixed positions against the viewport.
  • sticky stays in flow until a scroll threshold, then behaves like fixed inside its container. It needs a top, bottom, left, or right value to start.

A sticky element only sticks while its parent is in view; that is the usual reason a header stops sticking halfway down a page.