Forum Moderators: not2easy
For example, for the body, I'd like them all to have a 5% margin. But for some of them I'd like to have a blue background, and for some of them I'd like to have a green background.
Possible code is below.
External style sheet for all pages (110 pages)
body
{
margin: 5%;
background-color: blue;
}
External style sheet for section 3 (20 pages)
body
{
background-color: green;
}
What I'm trying to do is have a 5% margin on all pages, with a blue background on 90 pages, and green on the other 20 pages. One solution is to add margin: 5%; to the second style sheet, but I'm trying not to be redundant and put the same information in two different style sheets. What I'd like to do is reference two different external style sheets on one web page. Is there a way to do that?
Help!
This is where css specificity comes into play. (google it, it's not too terribly hard)
When the css selector (in this case body) have the same specificity the latter should take precedence.
So if you include your css file for everything first, then your specific one second, the background-color: green; rule should be applied.
If it is not, you could just add !important to the rule:
background-color: green !important;
But, it's better to use specificity if you can