0
0

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 1 year has passed since last update.

!importantについて

Posted at

!importantとは

!importantとは、CSSにおけるプロパティの優先順位を無視して、強制的に優先する命令です。

style.css
h1 {
    color: blue !important;
}

例えば、h1セレクタに対し!importantを使用する場合、他のCSSプロパティでh1のcolorプロパティを変更しようとしても、!importantを使用したプロパティを最優先にして使用することができる。

セレクタの優先順位とは

  1. テキストセレクタの優先順位は、セレクタ < class < id < style の順番

    index.html
    <div class="top" id="top" style="color:red;">サンプル</div>
    
    style.css
    div {
        color: yellow;
    }
    .top {
        color: green;
    }
    #top {
        color: blue;
    }
    

    上記の場合、colorはredが優先される。

  2. 同じセレクタなら、後から書いた物が優先される

    style.css
    .top {
        color: red;
    }
    .top {
        color: blue;
    }
    

    上記の場合、blueが優先される。

参考にしたサイト

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?