diff --git a/snippets/sibling-fade.md b/snippets/sibling-fade.md new file mode 100644 index 000000000..06261c13b --- /dev/null +++ b/snippets/sibling-fade.md @@ -0,0 +1,71 @@ +### Sibling fade + +Fades out the siblings of a hovered item. + +#### HTML + +```html +
+ Item 1 + Item 2 + Item 3 + Item 4 + Item 5 + Item 6 +
+``` + +#### CSS + +```css +span { + padding: 0 1rem; + transition: opacity 0.2s; +} + +.sibling-fade:hover span:not(:hover) { + opacity: 0.5; +} +``` + +#### Demo + +
+ +
+ + + +#### Explanation + +1. `transition: opacity 0.2s` specifies that changes to opacity will be transitioned over 0.2 seconds. +2. `.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`. + +#### Browser support + +✅ No caveats. + +