Control Parent from Child with :has()
CODE PREVIEW
P
Prompt
Create a demo showing how CSS :has() selector can style parent elements based on child states. Include interactive examples like checkbox toggle, hover effect, and active state.
CSSの:has()擬似クラスを使うと、子要素の状態に応じて親要素をスタイリングできます。このデモでは3つのインタラクティブな例を紹介:チェックボックスで親の枠線と背景が変化、スパンにホバーで親が拡大、ボタンを押し続けるとコンテナの色が変わります。JavaScript不要、純粋なCSS条件付きスタイリングです。
Prompt Overview
The CSS :has() pseudo-class allows styling a parent element based on the state of its children. This demo shows three interactive examples: a checkbox toggles the parent's border and background, hovering over a span transforms the parent, and pressing a button changes the container's color. No JavaScript required — pure CSS conditional styling.
Was this prompt helpful?
Comments
Comments appear after moderation