0

I have multiple elements with the class .foo:

<a href="#" class="foo">Hello!</a>
<a href="#" class="foo">¡Hola!</a>
<a href="#" class="foo">Bonjour !</a>

When I hover over one of those, I want to be able to apply styling to all .foo elements, except the one that has been hovered over.

I suppose I'm looking for the CSS equivalent to $(this) in jQuery.

Something like this, perhaps:

.foo:hover::not(this) {
    color:fuchsia;
}
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Obvious_Grapefruit
  • 640
  • 1
  • 8
  • 21

1 Answers1

1

Consider a container for your elements and you can easily do this:

.box {
 display:inline-block;
}
.box:hover a {
  color:red;
}
.box a:hover {
  color:initial;
}
<div class="box">
<a href="#" class="foo">Hello!</a>
<a href="#" class="foo">¡Hola!</a>
<a href="#" class="foo">Bonjour !</a>
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415