I have menu which the active item has an active class on load, which changes its background.
The hover of other items change the background of hovered item.
<ul>
<li></li>
<li class="active"></li>
<li></li>
</ul>
<style>
li:hover, li.active {background:black}
</style>
Is there any way to remove active class background on other items hover in pure CSS. something like:
li.hover .active {background:none}
This works if active is under li, but doesn't work here.
This worked for me :
Try this:
This has a few conditions:
:not
pseudo-tagul
must not have too much padding or empty space, otherwise you could activate the:hover
of theul
without hovering over anyli
sThis isn't reliably possible with CSS, as CSS can only affect elements that appear later in the DOM, not previously, so hovering over the first
li
can affect the currentli.active
element with the following CSS:JS Fiddle demo.
But hovering over the third
li
cannot affect the sameli.active
element.However, the following would work:
JS Fiddle demo.