0

I have this DOM Tree:

<ul id="menu-horizontalnav" class="menu">

    <li id="menu-item-19">

        <ul class="sub-menu">
            <li id="menu-item-99" ></li>

        </ul>
    </li>

</ul>

Now I want that the <ul class="sub-menu"> and his child content is hidden. I added a new .css rule to my style.css file:

enter image description here

But as you can see it gets overriden by this rule:

enter image description here

If I deactivate display: block; everything works.

My Quesiton is how can I add a .css rule which is only valid for the class="sub-menu" without getting this rule overriden by the rule .menu ul

In my Understanding from the .css rules the display: none; rule should override the display: block; rule, because it is deeper in the hiracy

I added my code in the style.css file in my child theme

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Viktor Carlson
  • 989
  • 1
  • 13
  • 36

3 Answers3

1

Add

  hideMenu
  {   
    display:none !important;
  }

Whenever you want to hide , add this class using addClass or just add the property alone.

Whenever you want to remove this, removeClass or remove the property.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Gibbs
  • 21,904
  • 13
  • 74
  • 138
1

A trivial way would be to overwrite the CSS rule by marking it as important:

.sub-menu {
    display: none !important;
}

But this technique should be avoided if at all possible for various reasons.

The better way would be to explicitely address the place the sub-menu class takes in the DOM hierarchy in your css:

.menu ul.sub-menu {
    display: none;
}

This instruction is more specific than just using .menu ul and will thus be preferred by the browser.

Community
  • 1
  • 1
mritz_p
  • 3,008
  • 3
  • 28
  • 40
1

Just add the following css:

ul .submenu {display:none !important;}

It should solve your problem and override the ul.menu class

Philip
  • 395
  • 1
  • 5
  • 15