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.
Classes
Section titled “Classes”| 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.
Choosing a value
Section titled “Choosing a value”relativekeeps the element in flow and becomes the containing block for absolutely positioned children.absolutetakes the element out of flow and positions it against the nearest positioned ancestor.fixedpositions against the viewport.stickystays in flow until a scroll threshold, then behaves likefixedinside its container. It needs atop,bottom,left, orrightvalue 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.