freecoding.school100% FREE · NO SIGNUP
Neon DistrictISSUE #23 of 50

pseudo-classes · :has() · the parent selector

PrismaVSJank the Janitor
Prisma says:has() is the long-awaited parent selector — style an element based on what it contains.

:has() finally lets CSS look downward: article:has(img) styles articles containing an image; label:has(input:checked) reacts to a checked child. It enables logic that used to require JavaScript — highlighting a card with an alert inside, styling an invalid form row, and more.

Power-ups you unlock

Jank the Janitor attacks — common mistakes

Boss battleStyle a card differently when it :has(.badge).

Example code

<!doctype html><html><head><meta charset="utf-8">
<style>.card{padding:14px;background:#140a28;color:#e6e0ff;margin:6px}.card:has(.badge){border:2px solid #b388ff}</style></head><body style="background:#06040d;padding:20px"><div class="card">plain</div><div class="card"><span class="badge">★</span> has a badge</div></body></html>
▶ Open the interactive comic issue
‹ Pseudo-Classes · :Is() · :Where() · :Not()Pseudo-Elements · ::Before · ::After ›