Helpers
Position
Fixed and sticky helpers for headers, footers and sidebars, with the theme's z-index values.
How it works
Four classes pin an element to the viewport or to its scroll container. They use the theme's z-index
scale: 120 for fixed and 110 for sticky. Both sit above dropdowns
(100) and below offcanvas (195) and modals (205), so a fixed navbar
paints over a dropdown opened further down the page. See Z-index for
the full ladder.
For plain position values (.position-relative, .top-0,
.translate-middle) use the position utilities.
Fixed top
Pins to the top of the viewport, edge to edge. Pair it with top padding on <body> so
content does not start underneath it. The navbar page shows the
pattern.
<nav class="navbar fixed-top">…</nav>
Fixed bottom
<footer class="fixed-bottom">…</footer>
Sticky top
Scrolls with the page until it reaches the top, then stays. Sticky is relative to the nearest scrolling ancestor, which is why the demo below works inside a 220px box.
<div class="sticky-top">…</div>
- Match 1 — Opener, 8:42
- Match 2 — Tag team, 11:05
- Match 3 — Cruiserweight, 9:50
- Match 4 — Hardcore rules, 13:12
- Match 5 — Women's title, 10:30
- Match 6 — Intercontinental, 15:18
- Match 7 — Tag titles, 14:44
- Match 8 — Steel cage, 19:20
- Match 9 — Main event, 24:03
HTML
<div class="docs-scroll-demo bg-body-tertiary">
<div class="sticky-top text-bg-navy px-3 py-2 fw-bold">Results · scroll the box</div>
<ol class="list-group list-group-flush">
<li class="list-group-item">Match 1 — Opener, 8:42</li>
<li class="list-group-item">Match 2 — Tag team, 11:05</li>
<li class="list-group-item">Match 3 — Cruiserweight, 9:50</li>
<li class="list-group-item">Match 4 — Hardcore rules, 13:12</li>
<li class="list-group-item">Match 5 — Women's title, 10:30</li>
<li class="list-group-item">Match 6 — Intercontinental, 15:18</li>
<li class="list-group-item">Match 7 — Tag titles, 14:44</li>
<li class="list-group-item">Match 8 — Steel cage, 19:20</li>
<li class="list-group-item">Match 9 — Main event, 24:03</li>
</ol>
</div>Responsive sticky top
.sticky-{sm|md|lg|xl|xxl}-top sticks only from that
breakpoint up. Below it the element flows normally — useful for a
sidebar that should pin on desktop but stack on phones.
<div class="sticky-sm-top">Sticky on viewports sized SM (small) or wider</div>
<div class="sticky-md-top">Sticky on viewports sized MD (medium) or wider</div>
<div class="sticky-lg-top">Sticky on viewports sized LG (large) or wider</div>
<div class="sticky-xl-top">Sticky on viewports sized XL (extra-large) or wider</div>
<div class="sticky-xxl-top">Sticky on viewports sized XXL (extra-extra-large) or wider</div>
Sticky bottom
Same idea, pinned to the bottom edge of the scroller while the rest scrolls past.
<div class="sticky-bottom">…</div>
- Row 1 — Championship history
- Row 2 — 1985 · inaugural champion
- Row 3 — 1988 · 412-day reign
- Row 4 — 1991 · vacated
- Row 5 — 1994 · tournament final
- Row 6 — 1997 · unified
- Row 7 — 1999 · ladder match
- Row 8 — 2002 · belt retired
HTML
<div class="docs-scroll-demo bg-body-tertiary">
<ol class="list-group list-group-flush">
<li class="list-group-item">Row 1 — Championship history</li>
<li class="list-group-item">Row 2 — 1985 · inaugural champion</li>
<li class="list-group-item">Row 3 — 1988 · 412-day reign</li>
<li class="list-group-item">Row 4 — 1991 · vacated</li>
<li class="list-group-item">Row 5 — 1994 · tournament final</li>
<li class="list-group-item">Row 6 — 1997 · unified</li>
<li class="list-group-item">Row 7 — 1999 · ladder match</li>
<li class="list-group-item">Row 8 — 2002 · belt retired</li>
</ol>
<div class="sticky-bottom text-bg-gold px-3 py-2 fw-bold">Total: 8 reigns</div>
</div>Responsive sticky bottom
<div class="sticky-sm-bottom">Sticky on viewports sized SM (small) or wider</div>
<div class="sticky-md-bottom">Sticky on viewports sized MD (medium) or wider</div>
<div class="sticky-lg-bottom">Sticky on viewports sized LG (large) or wider</div>
<div class="sticky-xl-bottom">Sticky on viewports sized XL (extra-large) or wider</div>
<div class="sticky-xxl-bottom">Sticky on viewports sized XXL (extra-extra-large) or wider</div>
CSS
.fixed-top { position: fixed; top: 0; right: 0; left: 0; z-index: 120; }
.fixed-bottom { position: fixed; right: 0; bottom: 0; left: 0; z-index: 120; }
.sticky-top { position: sticky; top: 0; z-index: 110; }
.sticky-bottom { position: sticky; bottom: 0; z-index: 110; }
Sass: $zindex-fixed: 120 and $zindex-sticky: 110 in
scss/_variables.scss. Sticky fails silently if an ancestor has overflow: hidden
or if the element is taller than the scroller.