CSS Overflow Hidden Not Working — Fix (2026) | Tutorials Logic
Why is Overflow Hidden Not Working?
The overflow: hidden property clips content that extends beyond an element's bounds. However, it doesn't work in all situations — particularly with position: fixed children, elements that create new stacking contexts, or when the overflow is on the wrong element.
Common Symptoms:
Content still visible outside container • Fixed elements ignoring overflow • Scrollbar still appearing
Content still visible outside container • Fixed elements ignoring overflow • Scrollbar still appearing
Common Causes
Quick Fix (TL;DR)
/* ❌ Fixed child escapes overflow: hidden */
.container { overflow: hidden; }
.child { position: fixed; } /* Ignores overflow! */
/* ✅ Use clip-path for fixed children */
.container { clip-path: inset(0); }
/* ✅ Or change fixed to absolute */
.container { position: relative; overflow: hidden; }
.child { position: absolute; } /* Respects overflow */
Common Scenarios & Solutions
Scenario 1: Fixed Child Escaping Container
/* ❌ position: fixed is relative to viewport, not parent */
.modal-container { overflow: hidden; }
.modal { position: fixed; top: 0; left: 0; } /* Ignores overflow! */
/* ✅ Use transform on parent to contain fixed children */
.modal-container {
transform: translateZ(0); /* Creates containing block for fixed */
overflow: hidden;
}
/* ✅ Or use clip-path */
.modal-container { clip-path: inset(0 round 8px); }
Scenario 2: Clearing Floats
/* ❌ Container collapses with floated children */
.container { /* No height — collapses! */ }
.child { float: left; height: 200px; }
/* ✅ overflow: hidden clears floats */
.container { overflow: hidden; }
/* ✅ Modern clearfix */
.container::after {
content: '';
display: table;
clear: both;
}
/* ✅ Best: Use flexbox instead of floats */
.container { display: flex; }
Scenario 3: Prevent Page Scroll
/* ✅ Prevent body scroll (e.g., when modal is open) */
body.modal-open {
overflow: hidden;
}
/* ✅ Prevent horizontal scroll */
body {
overflow-x: hidden;
}
/* ✅ Note: overflow-x and overflow-y are separate */
.container {
overflow-x: hidden; /* Only hide horizontal overflow */
overflow-y: auto; /* Allow vertical scroll */
}
Scenario 4: Image Overflow in Card
/* ✅ Clip image to card with border-radius */
.card {
border-radius: 12px;
overflow: hidden; /* Clips image corners */
}
.card img {
width: 100%;
height: 200px;
object-fit: cover; /* Fill without distortion */
}
Best Practices to Avoid This Error
Related Issues
Key Takeaways
- overflow: hidden clips content that extends beyond the element's bounds
- position: fixed children always escape overflow: hidden — they're relative to the viewport
- Use transform: translateZ(0) on the parent to contain fixed children
- overflow: hidden on a float container clears the floats (establishes BFC)
- Use overflow-x and overflow-y separately for more precise control
- clip-path is more powerful than overflow for complex clipping shapes
Frequently Asked Questions
Level Up Your Css Skills
Master Css with these hand-picked resources
10,000+ learners
Free forever
Updated 2026
Related CSS Topics