Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make entire CSS sheet !important

Tags:

css

stylesheet

Is there a way to make an entire CSS Style sheet take precedence over another? I know you can do the !important but can I do that with one line rather than modify all thousand properties on the sheet?

Thanks!

like image 735
JD Audi Avatar asked Apr 02 '11 23:04

JD Audi


People also ask

How do you make an entire CSS class important?

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!

How do you include important in CSS?

The ! important keyword (or statement) must be placed at the end of the line, immediately before the semicolon, otherwise it will have no effect (although a space before the semicolon won't break it) If for some particular reason you have to write the same property twice in the same declaration block, then add !


2 Answers

Make sure the stylesheet you want is called last (or a specific style you want is called last). For example, using this:

span { color: red; }
span { color: blue; }

...will turn all text in <span>'s blue. Take a look here.

like image 198
Shaz Avatar answered Sep 19 '22 17:09

Shaz


Rules with identical specificity that come later will overrule previous ones, so if both style sheets contain the identical selectors, you should be able to do this by just loading the one before the other.

If they contain different selectors, like

#navigation h3 { color: red }

and

.mainpage .navmenu h3 { color: blue }

you are likely to get specificity conflicts. The only blanket solution for that is indeed !important (although that is really, really terrible architecturally. Are you sure you need this? Maybe explain why, it's possible somebody is able to come up with a better solution.)

There is, however, no single-line directive to elevate the "importance" of one style sheet over the other.

like image 22
Pekka Avatar answered Sep 20 '22 17:09

Pekka