Help ! IE Only Styles Advice Needed

Hey all, I am wanting to know something…

I have the following :


<!--[if lt IE 7 ]> <html class="ie ie6 no-js" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 7 ]>    <html class="ie ie7 no-js" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 8 ]>    <html class="ie ie8 no-js" <?php language_attributes(); ?>> <![endif]-->
<!--[if IE 9 ]>    <html class="ie ie9 no-js" <?php language_attributes(); ?>> <![endif]-->
<!--[if gt IE 9]><!--><html class="no-js" <?php language_attributes(); ?>><!--<![endif]-->
<!-- the "no-js" class is for Modernizr. -->

Of course all of this is new to me. I was hoping someone can tell me what this is all about…

Also, lets say I want to use an IE Fix’s on an Stylesheet. Example–> ie7 header { background-color: # 000;}, but I don’t want allot of this on my main CSS Stylesheet. Is there a way to link to an IE Only Stylesheet for IE9 and below? I mean a link from a Stylesheet to another Stylesheet?

Thank you…

The above code adds a class to the html element depending on what version of IE is viewing the page.

e.g. If IE6 is the browser viewing the page the html element will have a class like this:

<html class=“ie6”>

Therefore if you need special rules for IE6 you can use that class to precede them.

e.g.

.ie6 #header{background:red}

The same applies of the other versions of IE should you need to supply alternative rules.

The benefits of this approach are that you don’t need multiple stylesheets which are a pain to maintain. The drawbacks are that you have the hacks in the main stylesheet. If you would rather maintain separate stylesheets for your IE hacks then just use conditional comments in the normal way.

The class method can have an impact on specificity due to the weight of the extra class and the external stylesheet method can upset the cascade order if you have over-ridden rules later on in the stylesheet.

In the end the best method is to avoid hacks and try and work around the problem without resorting to them at all or at least minimise their use.