What does !important mean in CSS?

后端 未结 5 1334
后悔当初
后悔当初 2020-11-21 23:32

What does !important mean in CSS?

Is it available in CSS 2? CSS 3?

Where is it supported? All modern browsers?

5条回答
  •  误落风尘
    2020-11-22 00:18

    The !important rule is a way to make your CSS cascade but also have the rules you feel are most crucial always be applied. A rule that has the !important property will always be applied no matter where that rule appears in the CSS document.

    So, if you have the following:

    .class {
       color: red !important;
    }
    .outerClass .class {
       color: blue;
    }
    

    the rule with the important will be the one applied (not counting specificity)

    I believe !important appeared in CSS1 so every browser supports it (IE4 to IE6 with a partial implementation, IE7+ full)

    Also, it's something that you don't want to use pretty often, because if you're working with other people you can override other properties.

提交回复
热议问题