views:

202

answers:

2

I'm needing to use a different stylesheet for IE, and I'm wondering about which stylesheet will take control.

For example, I'll use this code in the <head>:

<link rel="stylesheet" type="text/css" href="styles/style.css" />
<!--[if IE]><link rel="stylesheet" type="text/css" href="styles/ie.css" /><![endif]-->

Then will I need to use !important everywhere in the IE stylesheet? Or will the second stylesheet be seen as more important by IE? Does the order matter?

+7  A: 

Whichever style has the highest specificity will win. If you are providing the same selectors in both stylesheets the latest one will win. Otherwise, from the article I linked above:

  1. Specificity determines, which CSS rule is applied by the browsers.
  2. Specificity is usually the reason why your CSS-rules don’t apply to some elements, although you think they should.
  3. Every selector has its place in the specificity hierarchy.
  4. If two selectors apply to the same element, the one with higher specificity wins.
  5. There are four distinct categories which define the specificity level of a given selector: inline styles, IDs, classes+attributes and elements.
  6. You can understand specificity if you love Star Wars: CSS Specificity Wars.
  7. You can understand specificity if you love poker: CSS Specificity for Poker Players
  8. When selectors have an equal specificity value, the latest rule is the one that counts.
  9. When selectors have an unequal specificity value, the more specific rule is the one that counts.
  10. Rules with more specific selectors have a greater specificity.
  11. The last rule defined overrides any previous, conflicting rules.
  12. The embedded style sheet has a greater specificity than other rules.
  13. ID selectors have a higher specificity than attribute selectors.
  14. You should always try to use IDs to increase the specificity.
  15. A class selector beats any number of element selectors.
  16. The universal selector and inherited selectors have a specificity of 0, 0, 0, 0.
  17. You can calculate CSS specificity with CSS Specificity Calculator.

Here are the official docs on it.

Paolo Bergantino
+1  A: 

The second declaration will override the first in ie.

AlteredConcept