.no-scroll
class with overflow: hidden
, height: 100vh
, and position: fixed
to both html
and body
when the menu opens..no-scroll
class based on dropdown open state..w-nav-overlay
doesn’t interfere by limiting its height with max-height: 100vh
and adding overflow-y: auto
if needed.You're trying to prevent background scrolling when a dropdown menu (overlay) appears in Webflow, but standard methods like overflow: hidden
or position: fixed
aren't working due to .w-nav-overlay
extending the full height of the page.
overflow: hidden
Fails by Default.w-nav-overlay
is appended at the body end, applying overflow: hidden
to the body
doesn’t stop scrolling because the html
tag can still scroll.overflow: hidden
to the html
and body
overflow: hidden
to both html
and body
elements when the dropdown/overlay is open..no-scroll
to both html
and body
when the menu opens, and remove it when closed.Go to Page Settings > Before
tag and insert:
```javascript
```
Replace .w-dropdown-toggle
with your actual dropdown trigger class if different.
.no-scroll
CSS RuleIn your Webflow project, go to Project Settings > Custom Code > Head or use an embedded <style>
element in the page.
```html
```
.w-nav-overlay
is not detached from the scrolling context. If it’s appended to <body>
independently, ensure it doesn’t independently expand past the viewport:max-height: 100vh
and overflow-y: auto
on .w-nav-overlay
if needed.To stop background scrolling behind an open dropdown or mobile menu, apply a custom .no-scroll
class to both the html
and body
elements using Webflow's Webflow.push()
inside a <script>
. Also, define CSS to lock scroll properly. This prevents body scrolling even when overlays stretch the page height.