views:

116

answers:

4

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?

A: 

There aren't inherently any browser incompatibility issues that I know of. Just make sure that you're testing in all the browsers you care about with each step and you should be fine.

Your example of 'bold blue' is correct. It should work that way.

You should take a moment and read about CSS specificity and inheritance. These links will explain how CSS values are "merged" between multiple rules on the same selector.

jessegavin
A: 

I don't think there are any incompatibilities. Just make sure, that the specificity of your overrides is greater than the "original's" or if they have the same specificity, the override is declared after the "original".

More about specificity: http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/

Dave
Definitely. We'll make sure we're calling directly to the style needed by defining the hierarchy correctly. I just wanted to make sure that even all the way back to IE6 my styles/overrides work and that no random browser is going to screw me at the end of the day.
Will Ashworth
There's no way to account for all random browsers. You really need to decide which browsers you're going to test with. I am guessing you're not going to worry about Netscape 3. Just create your list and test, test, test along the way.
jessegavin
A: 

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.

YouBook
You should be more specific and say that IE6 doesn't support it properly and that IE7+ does support it.
jessegavin
I just got word that the version we plan to support (currently waiting on client approval) are: FireFox 2+, Internet Explorer 7+, Safari 3+, Chrome 1+
Will Ashworth
A: 

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.

Jakub