I'm working on a pretty large website that has a big stylesheet already on the website. We're working with this large corporation with limited ability to make changes (no full access).
We'll be applying some new styles for a specific section on the website and we've been given the green light to include a second override stylesheet (in addition to the global one) if needed.
My question is this. Are there any browser incompatibility issues we need to be aware of if using this method? Due to the popularity of this website and how many views they receive daily, we'll need to be as compatible as possible and I'm just wanting to make sure that our CSS overrides for the sections we're working with go off without a hitch.
I've heard of some rumors that IE may not handle the overrides correctly. Here's an example of the nature of the types of style overrides we'll be doing...
if i have body { color:blue; } and body { font-weight:bold; } in the second CSS file, we'll get blue and bold right?
To override the CSS properties of a class using another class, we can use the ! important directive. In CSS, ! important means “this is important”, and the property:value pair that has this directive is always applied even if the other element has higher specificity.
Answer. Yes, you can apply more than one stylesheet to an HTML file. For each stylesheet you link to a page, you would just need to add an additional <link> element.
Inline styles added to an element (e.g., style="font-weight: bold;" ) always overwrite any normal styles in author stylesheets, and therefore, can be thought of as having the highest specificity.
What you are describing with your CSS is inheritance, and essentially it will 'stack' your css definitions, so as you made the example of body { color: blue } , body { font-weight: bold; } you will end up with both values for body via inheritance (not overriding!)
To counter the inheritance, you would need to zero out, or elminate the primary css sheets defnition.
so if you had the example:
body { padding: 5px; color: red }
and you wanted to have a 3px margin with font color blue in your 2ndary sheet you would do the following to counter the inheritance
body {padding: 0px; margin: 3px; color: blue }
That way you would zero out the padding (to 0, if you so wished, effectively canceling it out). Color would be overwritten, and margin would be the new value added.
I would suggest (if you already don't) to use Firefox with firebug enabled (dual screens help here greatly, but not needed). Firebug will show you which lines are canceled out due to inheritance and in essence are overwritten.
You could also utilize your own classes, and double (or more) up on the class definition like so:
.red { color: red; }
.center { text-align: center; }
.w500px { width: 500px; }
<div class="red center w500px">This text is red and centered</div>
This way you just combine the values into one. Might give you another idea on how to go about something differently.
Hope that helps.
If there are inflicting styles then you could use the
body {
color: #000 !important;
}
!important overrides the style. Sadly, IE does not support this though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With