Question

I'm using conditional statements to load css for a specific version of IE or any other browser.

For example, let's say I'm targeting IE7.

So I'll use this:

    <!--[if IE 7]>
        <link rel="stylesheet" href="/style/ie7.css" />
    <![endif]-->

Now... this works when I'm using IE7 but I wanted that to also work for any other browser. When I check on firebug, this css is not loaded.

How can I make it work for IE7 and any other browser?

Thanks!

Was it helpful?

Solution

You could do this:

<!--[if IE 7]><!-->
    <link rel="stylesheet" href="/style/ie7.css" />
<!--<![endif]-->

Notice how the syntax highlighting changes because the link element is no longer commented out by the conditional statements.

The only caveat is that IE10 and later will also use this stylesheet, because IE10 and later now ignore HTML conditional statements entirely by design. Since IE10 is pretty well-regarded in terms of standards compliance, this should not be a problem, but if you don't want any version of IE except 7 to use this stylesheet, I don't think there's a workaround for it that doesn't involve JavaScript.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top