Patch Bandit

The story / The lab

Peanut · 2026-11-22

CSS parent selector with :has()

A CSS parent selector lets a box change its own look based on what is happening inside it, like a card lighting up when you check its box or dimming the other cards in a row. For twenty years that took JavaScript; now :has() does it in one line of CSS.

No toggle classes, no click listeners, no extra script bundle.

Snick the raccoon inspecting code

Check a card, watch the parent and siblings react

Click any card below (or tab to a checkbox and press Space). The checked parent lights up with a mint rim while unchecked siblings step back into dashed frames — zero JavaScript.

0 cards checked — all three cards sit at full weight.Selection active — checked parent is highlighted and unchecked siblings step back.All three cards checked — every parent matches :has(input:checked).

How the CSS :has() selector works

Normal CSS only looks down the page tree: from a parent to its children, or from one item to the next sibling. The CSS :has() selector lets you look up and sideways too.

  1. Style the parent: .card:has(input:checked) matches the card itself whenever a checked input sits inside it.
  2. Quiet the siblings: .deck:has(input:checked) .card:not(:has(input:checked)) checks whether the whole group has an active pick, then softens only the cards that are not checked.
  3. Drive status bars: Even the readout line under the cards above flips using pure CSS :has() — no script touches the DOM.

Sibling dimming on hover or focus

Move your pointer across the rows below (or press Tab through them). The active row steps forward while its siblings tuck back quietly.

Copy the CSS :has() code

Parent card highlight and sibling dimming (HTML and CSS)
<div class="deck">
  <label class="option">
    <input type="checkbox" />
    <span>Mint hoodie</span>
  </label>
  <label class="option">
    <input type="checkbox" />
    <span>Gold flashlight</span>
  </label>
  <label class="option">
    <input type="checkbox" />
    <span>Pocket wrench</span>
  </label>
</div>

<style>
  /* 1. Style the parent card when its checkbox is checked */
  .option:has(input:checked) {
    border-color: #86e3be;
    background: #2b1a42;
    transform: translateY(-3px);
  }

  /* 2. Soften unchecked siblings once at least one card is checked */
  .deck:has(input:checked) .option:not(:has(input:checked)) {
    border-style: dashed;
    background: #140a22;
    transform: scale(0.98);
  }
</style>

Hover and keyboard sibling dimming (CSS)
/* Spotlight the hovered or keyboard-focused item and quiet its siblings */
.row-list:has(.row-btn:hover, .row-btn:focus-visible)
  .row-btn:not(:hover, :focus-visible) {
  border-color: transparent;
  background: #140a22;
}

.row-btn:hover,
.row-btn:focus-visible {
  border-color: #86e3be;
  background: #2b1a42;
}

Browser support: The CSS :has() selector is Baseline Widely Available across current Chrome, Edge, Safari, and Firefox (supported in all major engines since late 2023). Older browsers ignore the :has() rule while checkboxes and buttons keep working normally. Tested in Chromium only.

The fine print, in plain words

Why this is free

We're raccoons who think simple things shouldn't cost a monthly fee. We take techniques apart, explain them in plain words, and give them away. The code on this page is MIT licensed: copy it, change it, and share it.

This is one of twelve experiments so far. Our first browser tool (Bandit Codes) is live now, and the rest sit as ideas in the stash.