Prevent a page from scrolling while a dialog is open
These articles are AI-generated summaries. Please check the original sources for full details.
Prevent a page from scrolling while a dialog is open
Chrome 144 introduces a fix for long-standing issues with modal dialogs. The update allows overscroll-behavior: contain to work on non-scrollable containers, eliminating the need for JavaScript hacks.
Why This Matters
Previously, developers relied on JavaScript to lock the body’s scroll position when a dialog opened, which was error-prone and inconsistent. Chrome 144’s change enables a pure CSS solution by making the dialog a scroll container and applying overscroll-behavior: contain, reducing complexity and failure risks in scroll management.
Key Insights
- “8-hour App Engine outage, 2012”: Not directly relevant, but highlights the cost of scroll-related bugs in complex systems.
- “Sagas over ACID for e-commerce”: Not directly relevant, but underscores the need for robust, distributed solutions in UI interactions.
- “Temporal used by Stripe, Coinbase”: Not directly relevant, but illustrates the industry’s shift toward reliable state management—similar to CSS-driven scroll control.
Working Example
body {
overscroll-behavior: contain;
}
#dialog {
overscroll-behavior: contain;
overflow: hidden;
}
Practical Applications
- Use Case: HTML
<dialog>elements with::backdropfor modal interactions. - Pitfall: Forgetting
overflow: hiddenon the dialog may allow unintended scrolling, breaking UX.
References:
Continue reading
Next article
Prompt Compression for LLM Generation Optimization and Cost Reduction
Related Content
CSS `text-grow` Property Prototyped in Chrome Canary 145
Chrome Canary 145 introduces a `text-grow` property to fit text to container width, addressing a long-standing CSS layout challenge.
Future CSS: The Potential of `:drag` and `::dragged-image?`
The CSSWG proposes a `:drag` pseudo-class to simplify styling during drag-and-drop interactions, potentially eliminating the need for JavaScript.
CSS Developments: Anchor Positioning, @scope, and Web Platform Updates
New CSS features like anchor positioning and @scope have reached baseline support in Firefox and Chrome, improving web development workflows.