Search code examples
htmlcsswordpressdivi

CSS: disable scrolling


unfortunately I have a little problem with a CSS class I implemented on my website. The menu on the page is displayed by the CSS code. Unfortunately I can't manage to disable scrolling while the menu is open. I already tried using "position: fixed !important;" and "overflow". Somehow, it did not work.

Here is the CSS code:

<style>

/*****************************************/
/*********| FULLSCREEN MENU CSS |*********/
/*****************************************/

  
  
/* Move the hamburger to the right of the header */
  
.de-burger-menu .et_pb_menu__wrap {
  justify-content: flex-end !important;
}

/* Hide the desktop menu */

.de-burger-menu .et_pb_menu__wrap .et_pb_menu__menu {
  display: none !important;
}

/* Force the mobile version of the menu */

.de-burger-menu .et_pb_menu__wrap .et_mobile_nav_menu {
  display: block !important;
  align-items: center !important;
}

/* Fullscreen Menu Style when Opened*/

.de-burger-menu .opened #mobile_menu1 {
  width: 100vw !important; /* Make it span the full width of the viewport */
  position: fixed !important;
  top: 0em !important;
  left: 0vw !important;
  height: 100vh !important; /* Make it span the full height of the viewport */
  display: flex !important;
  justify-content: center !important;
  flex-direction: column !important;
  transition: visibility 0.3s, opacity 0.3s ease-in-out; /* Animate the menu to fade in */
  padding: 0 !important;
  background-color: #ffffff!important; /* Fullscreen menu background color */
}

/* Show fullscreen menu */

.de-burger-menu .opened #mobile_menu1 {
  opacity: 1 !important; /* Make it visible by setting opacity to 1 */
  visibility: visible !important; /* Show the menu */
}

/* Hide and fade out the Menu when closed */

.de-burger-menu .closed #mobile_menu1 {
  opacity: 0 !important; /* Make it invisible by setting opacity to 0 */
  visibility: hidden !important; /* Hide the menu */
  transition: visibility 0.3s, opacity 0.3s, left 1s, ease-in-out !important; /* Animate the menu to fade out */
}

/* Remove Bullets next to LI Elements */

.de-burger-menu #mobile_menu1 li {
  list-style: none !important;
  text-align: center !important;
  width: 100%
}

/* Make sure that the menu is above other elements */

.de-burger-menu .et_pb_menu__wrap span.mobile_menu_bar {
  z-index: 999999 !important;
}

/* Set the close icon for when the menu is open */

.de-burger-menu .et_pb_menu__wrap .opened .mobile_menu_bar:before {
  color: #562f2f !important; /* Icon color */
  content: "\4d" !important; /* Divi font icon to use for the close icon */
  left: -40px; /* Close icon position. You might need to play with this to make it look right */
}

/* Keep hamburger icon in fixed position on mobile */
.de-burger-menu .opened .mobile_menu_bar {
  position: fixed !important;
}

/* Remove mobile menu border */

.de-burger-menu .et_mobile_menu {
  border-top: none;
}

/* Make sure the menu items do not show a background */

.de-burger-menu .et_mobile_menu .menu-item-has-children>a {
  background-color: transparent;
}

/* Remove the hover background from the menu items and add hover animation */

.et_mobile_menu li a:hover {
  background-color: transparent;
  opacity: 1;
  transition: transform 0.3s ease-in-out !important; /* Animated the menu item when hovered */
  transform: scale(1.15); /* Enlarge the hovered menu item by 15% when hovered */
}

/* Remove menu item bottom borders */

.de-burger-menu .et_mobile_menu li a {
  border-bottom: none;
}
</style>

The website is: https://aureus-frankfurt.de/

I hope someone knows a solution.

Kind regards


Solution

  • Hi Welcome to the community:

    You can target the mobile opened class with :has and make the body overflow:hidden

    body:has(.mobile_nav.opened) { 
    overflow: hidden 
    }