overflow-hidden
is Killing Sticky BehaviorOne of the most common reasons position: sticky
stops working is because one of the parent elements has overflow: hidden
. In your case, it looks like the SidebarProvider
is the culprit:
<SidebarProvider className="overflow-hidden"> // ❌ This prevents sticky from working
🛠 Fix: Either remove the class or change it to overflow-visible
:
<SidebarProvider className="overflow-visible">
Even if your sticky element has the right styles, it won't work if any of its ancestors (like SidebarInset
) have overflow set in a way that clips content:
<SidebarInset className="overflow-auto"> // ❌ This could also break sticky
Try removing or adjusting this as well — especially if you don’t need scrolling on that container.
If you’re using a fixed
header like:
<TopNav className="fixed top-0 w-full" />
...then sticky
elements might not behave as expected because the page’s layout shifts. You’ll need to account for the height of the fixed header when using top-XX
values.
Here’s a cleaner version of your layout with the sticky-breaking styles removed:
<SidebarProvider> {/* Remove overflow-hidden */}
<AppSidebar />
<SidebarInset> {/* Remove overflow-auto if not needed */}
<TopNav />
<BannerMessage />
<main className="flex min-h-[100dvh-4rem] justify-center">
<div className="container max-w-screen-2xl p-3 pb-4 lg:p-6 lg:pb-10">
{children}
</div>
</main>
</SidebarInset>
</SidebarProvider>