Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
CSS

CSS: Fix a Sticky Header That Silently Stops Sticking Partway Down the Page Because an Ancestor’s Overflow Isn’t Set to Visible

- 21.10.26 - ErcanOPAK

🎨 The Sticky Header That Un-Sticks Itself Halfway Down

position: sticky only sticks relative to its nearest scrolling ancestor, and that ancestor is determined by the first parent in the chain whose overflow property is set to anything other than the default visible – including a value as seemingly unrelated as overflow: hidden applied purely to clip a decorative shadow, or overflow-x: hidden added somewhere up the tree to stop a layout from scrolling sideways. Once any ancestor sets that property, the sticky element’s scrolling context becomes that ancestor’s box instead of the page, and it stops sticking the instant you scroll past that ancestor’s own boundary – which, depending on layout, can be most of the way down a long page.

🔎 The Problem

.page-wrapper {
  /* added only to stop a decorative box-shadow from bleeding
     past the wrapper's rounded corners on one section */
  overflow: hidden;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
}

/* .site-header is inside .page-wrapper in the markup */

/* Result: the header sticks correctly at first, then stops sticking
   and scrolls away entirely once the page scrolls past the bottom
   edge of .page-wrapper's own box - because overflow: hidden made
   .page-wrapper, not the viewport, the header's scrolling container */

✅ Fix: Find the Ancestor That Accidentally Became the Scroll Container

  • Walk up the DOM from the sticky element in DevTools and check every ancestor’s computed overflow, overflow-x, and overflow-y values – the first one that isn’t visible is the actual scrolling container the sticky element is bound to, regardless of which element you’d intuitively assume is responsible.
  • If the overflow was only added for a visual effect (clipping a shadow, hiding an intentional horizontal scrollbar on one specific element), move that overflow declaration onto a more tightly scoped wrapper that doesn’t also contain the sticky element, so the clipping effect survives without becoming the sticky element’s scroll boundary.
  • When the overflow genuinely needs to live on an ancestor that also must contain the sticky element, restructure the sticky header to live outside that ancestor in the markup instead (a common pattern: move it to be a direct sibling higher up the tree, styled to visually overlap the section it used to be nested inside).

🚨 Why This Is Dangerous

  • Because the sticky behavior still works correctly for the first portion of the scroll, this usually isn’t caught until someone scrolls far enough down a long page during manual testing – a quick check near the top of the page looks completely fine and gives no indication the behavior breaks further down.
  • The overflow property responsible is very often unrelated code added much earlier for an entirely different visual reason, sitting several component layers away from the sticky element itself – debugging by staring at the sticky element’s own CSS alone will never find it, since the actual cause lives in a completely different part of the stylesheet.

position: sticky was never promising to stick to the page – it was promising to stick to its nearest scrolling ancestor, and overflow: hidden anywhere up the tree is exactly what quietly redefines which ancestor that is.

— UI Engineer

Related posts:

CSS: Fix a View Transition That Silently Never Animates Because Two Elements Share the Same view-tra...

CSS: Fix a View Transition That Silently Never Animates Because Two Elements Share the Same view-tra...

CSS: Use will-change to Optimize Animations Before They Start

CSS: Use will-change to Optimize Animations Before They Start

CSS — aspect-ratio Fixes Responsive Media Instantly

CSS — aspect-ratio Fixes Responsive Media Instantly

Views: 7

Post navigation

Windows 11: Fix File Explorer Search Silently Skipping Recently Edited Files Because Indexing Paused During Battery Saver
Git: Fix a Partial Clone That Silently Fails to Show a File’s Full History Because –filter Excluded Its Old Blobs

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (857)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (857)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com