-1

I am working on a WordPress website and my menu is appearing as,

<li  class="current-menu-parent current-menu-item "><a  href="#">SHOP</a>
    <ul class="sub-menu">
        <li class="menu-item-517 current-menu-item"><a href="#">Engine1</a></li>
        <li class="current-menu-item menu-item-516 current-menu-item"><a href="#">Engine2</a></li>
        <li class="menu-item-517 current-menu-item"><a href="#">Engine3</a></li>    
    </ul>
</li>

Engine2 is my currently active page. the class current-menu-item is repeating 2 times in my active sub menu li. How can I select my currently active submenu li using css?

I have tried with

.current-menu-item.current-menu-item{
}

but not working.

Please help me.....

here is the link to my website. Please visit the drop-down menu under shop.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
Nick
  • 40
  • 6

1 Answers1

0

How can I select my currently active submenu li using css?

Given your specific example; the element with the repeated class, has current-menu-item first, whereas the others do not. That being the case you can use "attribute begins with" operator: [attr^=value]. reference

[class^=current-menu-item]{
  background-color: yellow;
}
<li  class="current-menu-parent current-menu-item "><a  href="#">SHOP</a>
    <ul class="sub-menu">
        <li class="menu-item-517 current-menu-item"><a href="#">Engine1</a></li>
        <li class="current-menu-item menu-item-516 current-menu-item"><a href="#">Engine2</a></li>
        <li class="menu-item-517 current-menu-item"><a href="#">Engine3</a></li>    
    </ul>
</li>

This is very specific and prone to breaking if changes are made to your menu. The real fix would be to fix up the classes in your menu items.

Dan
  • 10,614
  • 5
  • 24
  • 35