body { overflow: hidden; } when .w-nav-overlay is open.max-height: 100vh; overflow: auto; to .w-nav-overlay via custom CSS to prevent the overlay from increasing page height and re-enabling background scroll.You're trying to stop background scrolling when a .w-nav-overlay dropdown is open, but standard fixes like overflow: hidden; or position: fixed; aren't working due to the overlay expanding the page height. Here's how to properly handle this in Webflow.
body Overflow Control via Interactions
overflow: hidden.overflow: auto (or visible).
If Interactions don't solve the issue, apply a custom script to control scrolling behavior.
</body> tag:
"This will track the navbar dropdown and toggle overflow for the body"
```js
<script>
const navDropdown = document.querySelector('.w-nav-overlay');
const body = document.body;
const observer = new MutationObserver(() => {
const isOpen = navDropdown && getComputedStyle(navDropdown).display !== 'none';
body.style.overflow = isOpen ? 'hidden' : 'auto';
});
if (navDropdown) {
observer.observe(navDropdown, { attributes: true, attributeFilter: ['style'] });
}
</script>
```
.w-nav-overlay is on your page before this script runs, or wrap it in a DOMContentLoaded check if it loads later.
The overlay likely increases page height due to absolutely or fixed-positioned children.
.w-nav-overlay and its children using Dev Tools.
```css
<style>
.w-nav-overlay {
max-height: 100vh;
overflow: auto;
}
</style>
```
Another option is to add a no-scroll class to the body when the overlay is open:
.no-scroll in Webflow:overflow: hidden on Body with .no-scroll.
```js
<script>
const dropdownToggle = document.querySelector('.w-nav-button');
const body = document.body;
dropdownToggle.addEventListener('click', () => {
setTimeout(() => {
const isOpen = document.querySelector('.w-nav-overlay[style*="display: block"]');
if (isOpen) {
body.classList.add('no-scroll');
} else {
body.classList.remove('no-scroll');
}
}, 100); // Delay needed to let Webflow apply styles
});
</script>
```
To prevent background scroll when a Webflow dropdown menu opens:
body dynamically using Interactions or JavaScript..w-nav-overlay height to 100vh with max-height.