0
0

More than 3 years have passed since last update.

CSS~!important~

Posted at

CSSには優先度というものがあります。
上から書いたものが、下に向かって反映されていきます。

例えば、このように記入したとしましょう。

index.html
<h1>今日は何をしていましたか??</h1>
style.css
h1 {
  color: red;
}

h1 {
  color:blue;
}

この場合、優先的に反映されるのは一番最後に記入されたcssになります。
スクリーンショット 2021-03-15 17.05.19.png

こうなりますね。
赤色を反映したいとしましょう。
ここで使うのが、『!important』です。
では先程のcssに付け加えていきます。

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

h1 {
  color:blue;
}

とすると、赤色が反映されました。
スクリーンショット 2021-03-15 17.09.04.png

ただし、このタグは本当に優先したいものに付けるようにしましょう!
使わないのがマストです😊

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