Day 181 - One‑Line :has() magic to push everything else to the background

Day 181 - One‑Line :has() magic to push everything else to the background

🎉 An Awesome CSS Link a Day - Day 181 🎉

One‑Line :has() magic to push everything else to the background

#AnAwesomeCSSLinkADay #YouDontMessWithCSS #CSS

I'm proud to present today's link from one of my best friends Marco Pollacci. Ever wanted to dim everything except the element under the cursor? With the new `:has()` relational pseudo‑selector, you can achieve a sleek focus effect using only CSS. We all know that we can call `:has()` a "content aware" selector.

📐 Theory

The `:has()` selector lets you select a parent based on a child state, making advanced interactions simple.

  1. :has() acts as a parent selector, matching an element when any inner element meets the condition.

  2. You can pair `:has(p:hover)` with `p:not(:hover)` to blur inactive siblings (eg. `div:has(p:hover) p:not(:hover) { filter: blur(3px); }`).

  3. Modern browsers (Chrome, Edge, Safari, Firefox) fully support `:has()`, so you can drop JavaScript for many interactivity patterns.

🚀 Today’s Link

🔗 One Line of CSS to Push Everything Else to the Background

💫 Giveaways

  • Single‑line blur technique using `:has()`

  • Clear explanation of selector logic and performance

  • Interactive sandbox to experiment immediately

❓ Why This Rocks

  • Removes JavaScript dependency for hover‑focus effects

  • Enhances readability by guiding the user’s attention

  • Easy to customize for lists, cards, menus, galleries

🗣️ Join the Conversation

  • Have you used `:has()` in production yet?

  • What other one‑liner CSS tricks are in your toolkit?

  • How would you adapt this blur pattern for accessibility?

Emiliano Pisu

🎥 Sensei & Co-Host @ DevDojo IT 🎤 Speaker ♿️ Accessibility WCAG Expert ✨ Turning Designs into interactive things 🦸♂️ Your friendly neighborhood Design Engineer

1mo

To view or add a comment, sign in

Others also viewed

Explore topics