I have a menu using pure CSS, hover a parent li
item display the the nested list. A simplified example:
<ul id="menu-top" >
<li class="menu-item">
<a href="http://localhost/wp5/forums/">Forums</a>
<ul class="sub-menu">
<li><a href="http://localhost/wp5/register/">Register</a></li>
<li><a href="http://localhost/wp5/activate/">Activate</a></li>
<li><a href="http://localhost/wp5/members/">Members</a></li>
</ul>
</li>
</ul>
The css:
.navigation ul.menu li:hover { background: #ccc} //hover the parent item changes it bg color
.navigation ul.sub-menu li {
display:none;
}
.navigation ul li:hover > ul.sub-menu li { display: block; }
It works ok, but I'm trying to add an "persistent" effect, I want keep the parent style set when hovering also the sub-item.
I tried this but can't get working:
.navigation ul.sub-menu li:hover > .navigation ul.menu li { background: #ccc}
I don't know if this is possible without javscript or else, also can't find anything about using ">" in CSS.
THanks for any help
:hover
is triggered on all ancestors of the element that is being hovered over, so.navigation ul.menu li:hover { background: #ccc; }
should work just fine.Alternatively, someday we should be able to use
:has()
.