15
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CSSAdvent Calendar 2017

Day 9

夢の疑似クラス: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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?