Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you read !important in CSS? [duplicate]

How is the CSS attribute property !important read?

Is it really important, exclamation mark important, ...?

Answer: From the answers below, it seems to be read simply important, or bang important.

like image 849
Randomblue Avatar asked Sep 10 '11 02:09

Randomblue


People also ask

How do you read important in CSS?

The ! important rule in CSS is used to add more importance to a property/value than normal. In fact, if you use the ! important rule, it will override ALL previous styling rules for that specific property on that element!

Can we use important in CSS?

In CSS, important means that only the ! important property value is to be applied to an element and all other declarations on the element are to be ignored. In other words, an important rule can be used to override other styling rules in CSS.

What is the alternative of important in CSS?

important is like a cheat-mode for CSS and it's not really advisable to use it in production. Normally the tools available for you to enable style overrides are: - specificity - the cascade order If you rely on the cascade order too much things can get difficult to debug, so in this situation, I'd use specificity.


2 Answers

an "!important" declaration (the delimiter token "!" and keyword "important" follow the declaration) takes precedence over a normal declaration.

http://www.w3.org/TR/CSS2/cascade.html#important-rules

Basically, where two style rules are the same... it gives the one marked !important greater importance and will apply those styles.

Example

div{     opacity:0 !important; }  div.jason{     opacity:1; } 

The first rule would be applied even though the second rule is more specific (one element + one class as opposed to one element)

Note: IE6 ignores !important when you have two of the same property and one of them is important - it'll always apply the last declaration, whether or not it was marked important. **Added from @BoltClock's comment below.

Warning: !important is a hammer that should only be used when absolutely necessary. Almost always, it is better to use more specific selectors to achieve greater specificity and have your styles applied the way you want. !important can make it very difficult for future developers to find and make changes to your code.

One good use case: !important is great for user-defined styles, where a user wants to manipulate Web site pages in specific way in his browser (say make all the backgrounds black and the text yellow). Without having to worry about specificity, the user can add styles to certain elements (like body) and make the styles render.

like image 163
Jason Gennaro Avatar answered Oct 12 '22 09:10

Jason Gennaro


Just "important" or "bang important." The ! is definitely not a negation in this case.


It's not a tag, it's a keyword.

like image 21
Matt Ball Avatar answered Oct 12 '22 09:10

Matt Ball