Styling siblings on hover in CSS

guerriero_se

Sebastiano Guerriero

Posted on May 27, 2020

Styling siblings on hover in CSS

Normally, you would need JavaScript to stylize all the siblings of an element you're interacting with. But wait! There's a cool method based 100% on CSS.

The idea, in short, is to target the :hover of the parent, then target all the children except the one you're hovering over.

.parent:hover .child:not(:hover) {
  /* this style affects all the children except the one you're hovering over */
}

Here's an example:

Originally published at CodyHouse.co

💖 💪 🙅 🚩
guerriero_se
Sebastiano Guerriero

Posted on May 27, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related