Files
30-seconds-of-code/snippets/sibling-fade.md
Angelos Chalaris d2c10f3e65 Deprecate browser support
Bump integration tools to 2.1.0
2020-04-29 13:47:57 +03:00

705 B

title, tags
title tags
Sibling fade interactivity,intermediate

Fades out the siblings of a hovered item.

<div class="sibling-fade">
  <span>Item 1</span> <span>Item 2</span> <span>Item 3</span> <span>Item 4</span>
  <span>Item 5</span> <span>Item 6</span>
</div>
span {
  padding: 0 1rem;
  transition: opacity 0.3s;
}

.sibling-fade:hover span:not(:hover) {
  opacity: 0.5;
}

Explanation

  • transition: opacity 0.2s specifies that changes to opacity will be transitioned over 0.3 seconds.
  • .sibling-fade:hover span:not(:hover) specifies that when the parent is hovered, select any span children that are not currently being hovered and change their opacity to 0.5.