What is the use of "!important" in css? [SOLVED] | SoloLearn: Learn to code for FREE!

+23

What is the use of "!important" in css? [SOLVED]

Please explain what is the difference between line 1 and line 2 line 1: display:block!important; line 2: display:block; why and where do we use "!important" ?

11/3/2018 4:54:20 PM

Suraj

15 Answers

New Answer

+28

!important is a directive to override inherited styling. E.g. styles for id selected element will override class selected element, however you can use !important to force render engine to use that rule. https://code.sololearn.com/Wa9h6A8c797N/?ref=app

+6

In simple words !important in any css gives it prior importance.

+6

Suraj the most important behaviour of ‘!important’ rule are 1. overriding INLINE styles on elements which are not have ‘!important’ in them. 2. the second use is to override long chains in selectors. so so as solution as code 3. the third is override partucular rules in case of classes that are responsible for behaviour. as example .hide {display: none!important} to be sure that element will be defenitely hidden also in case of overwritten display property etc

+5

A helpful question. Thanks a lot.

+4

don’t use it, it causes a lot of problems, organize your code instead.

+3

Suraj check out the code in my answer

+3

Lets say we have a code of Css: “div.Div1 { display: none; display: table !important “ Then Instead of “display: none” it will do the Most Important one(!important) one “display: table !important”.

+1

Here is the style rule code: https://code.sololearn.com/Wpjo8QJIXtVy/?ref=app You can do different things than this.

+1

It makes the style over any other is on the selector.

0

Lexus Collins, is it possible that browser could ignore line 2?

0

Lexus Collins, Thank !! I got this 😊😊😊

0

привет всем

0

0

-2

I think it means "Not Important"!