LoginSignup
15
12

More than 5 years have passed since last update.

夢の疑似クラス:has()

Posted at

:has()という疑似クラスがSelectors Level 4のEditor’s Draftにある。E:has(selector)で、selectorにマッチする要素を持つE要素を表す。これが広くサポートされれば、次のようなことが可能になる。

.fooを子孫に持つ.containerの中の.barにスタイルを当てる:

.container:has(.foo) .bar {
  color: red;
}

DOMツリー上に.fooがあるときに、.barにスタイルを当てる:

:root:has(.foo) .bar {
  color: red;
}

DOMツリー上の.fooがチェックされているときに、.barにスタイルを当てる:

:root:has(.foo:checked) .bar {
  color: red;
}
15
12
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
12