0
2

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.

CSSセレクタの詳細度 (優先順位)

Last updated at Posted at 2019-11-12

CSSセレクタの詳細度とは

ある要素へのCSSの指定が競合した場合、どのセレクタが優先されるかということ。

CSSセレクタの優先順位 (強さ順)

  1. HTMLのstyle属性
  2. id
  3. class、擬似クラス、属性
  4. 要素型、擬似要素

⚠️ 同じ優先順位の場合は後に書いたCSSが優先される。

<body>
  <div class="red">
    <h1>あああ</h1>
  </div>
</body>
.red {
  color: red;
}
div {
  color: black;
}

スクリーンショット 2019-11-12 17.38.46.png

classの方が要素型よりも強いので文字がredになる。

0
2
0

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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?