For the complete documentation index, see llms.txt. This page is also available as Markdown.

Add a Banner Above the Header

The announcement bar scrolls up and out of view while the main header follows it up, then stops and pins below the top of the screen. No gap, no jump, no double-height header.

This works whether the header resolves to position: sticky or position: fixed, so toggling data-overlay-header will not break it.

Before you start

Your header needs this structure, with the banner inside the Header Wrapper:

<header class="header-wrapper">   <!-- behavior shell, has the attached script -->
  <div class="header-banner">     <!-- announcement bar -->
  <div class="header">            <!-- logo + nav -->

Step 1: Understand why it doesn't work by default

.header-wrapper is the positioned box, so everything inside rides along with it, banner included.

The fix is to offset the wrapper upward by exactly the banner's height. The banner ends up above the viewport while .header lands at the top.

How much work that takes depends on which position the wrapper resolves to:

Attributes
Computed position
Who handles the timing

Sticky only

sticky

The browser. A static negative offset is enough.

Sticky + overlay

fixed

You. Fixed never waits for scroll.

position: sticky waits for scroll natively. position: fixed does not, so a negative offset applied to it takes effect at first paint and the banner would be gone before the visitor scrolls at all.

This guide supports both by publishing two CSS variables and letting each rule use only what it needs.

Step 2: Add the JavaScript

Paste this into the Header Wrapper's JavaScript panel at the very bottom. It is fully self-contained, so it can go anywhere in the file and nothing existing needs editing.

Four details worth understanding:

  • if (!bannerEl) return; means pages without a banner exit immediately and keep stock behavior.

  • The requestAnimationFrame throttle collapses scroll events down to one write per frame, since scroll fires far more often than the screen repaints.

  • The clamp plus the lastY guard means writes stop completely once you are past the banner. You pay for roughly the first 76px of scroll and nothing after.

  • { box: 'border-box' } matters because the ResizeObserver default is content-box, which ignores padding and border changes.

Step 3: Replace the Overlay & Sticky Header CSS

Open the Header Wrapper's CSS panel and find the /* ## Overlay & Sticky Header */ section. Use the comment navigation menu at the top left of the CSS editor to jump straight to it.

Replace everything from that comment down to (but not including) /* ### hide on scroll */ with the block below.

Last updated