Site logo

Archived topic

How to have the submenu navigation toggled down on open?

7 replies · Started by Stefan on March 3, 2023

Viewing posts 1–8 of 8

hello everybody,
I wonder if you can help me .
I want to have the submenu on show by default when I click the menu button on mobile view. how can I implement that ?
and can I use the css only for one navigation button and not for the whole navigation bar
the website is https://inkaholics.co.uk

Thank you in advance, Stefan

Hi Stefan,

Can you try this CSS:


.main-navigation.toggled .main-nav ul ul.sub-menu {
        position: relative;
        top: 0;
        left: auto!important;
        right: auto!important;
        width: 100%;
        pointer-events: auto;
        height: auto;
        opacity: 1;
        display: block;
        visibility: visible;
}

Hi thank yo u for the swift reply,
yes it works but when I press the little arrow on the right the dropdown doesn't retract .. also can't scroll down to the contacts .
wanted just the Artists one to be collapsed .
i have left live to see how it behaves

Hi there,

you won't be able to do it with CSS.
It would need some Javascript.

1. Create a new Hook Element ( in Appearance > Elements ).
2. In the hook text area add this script:


<script>
const clickme = document.querySelector('#menu-item-584 .dropdown-menu-toggle')
const elemHtml = document.querySelector('html')
const mutateOptions = {
  attributes: true
}

function callback(mutationList, observer) {
  mutationList.forEach(function(mutation) {
    if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
      // handle class change
      if (mutation.target.className == 'mobile-menu-open') {
        clickme.click();
      }
    }
  })
}

const observer = new MutationObserver(callback)
observer.observe(elemHtml, mutateOptions)
</script>

3. Set the Hook to: wp_footer
4. Set the Display Rules > Location to Entire Site
5. Publish the hook.

Hi David ,
It worked amazing , no problem whatsoever .thank you again for your support.
Regards,Stefan

Glad to hear that!

Very happy with the technical support, and the generate press theme . Thank you

Glad to be of help!

This archived topic is closed to new replies.