Sunday, 22 October 2017

CSS-Important.

Important

There is one thing that is even more specific than IDs: !important!important can be applied to specific attributes instead of full rules. It will override any style no matter how specific it is. As a result, it should almost never be used. Once !important is used, it is very hard to override.
The syntax of !important in CSS looks like this:
p { color: blue !important; } .main p { color: red; }
Since !important is used on the p selector’s color attribute, all p elements will appear blue, even though there is a more specific .main pselector that sets the color attribute to red.
The !important flag is only useful when an element appears the same way 100% of the time. Since it's almost impossible to guarantee that this will be true throughout a project and over time, it's best to avoid !important altogether. If you ever see !importantused (or are ever tempted to use it yourself) we strongly recommend reorganizing your CSS. Making your CSS more flexible will typically fix the immediate problem and make your code more maintainable in the long run.
Share:
Categories

0 comments:

Post a Comment