-2

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!

Mudassir
  • 1,136
  • 1
  • 11
  • 29
  • 2
    That conditional statement only loads the css if it's IE7. If you want it to load it for all browsers, remove the conditional statement. That said your question is very unclear. – Liam Apr 10 '14 at 15:05
  • 1
    What exacly are you trying to do and why. Conditional comments have been dropped by all new browsers including IE. – Paulie_D Apr 10 '14 at 15:06
  • Hence the word **new** in my comment. OP is asking about **all** browsers. – Paulie_D Apr 10 '14 at 15:07
  • `I wanted that to also work for any other browser`. If you're talking about making conditional comments work for non-IE browsers, other browsers did not have any sort of conditional comment support. It's an IE-only feature that was dropped in recent IE versions. – ajp15243 Apr 10 '14 at 15:09
  • Well... I look after a website that has 60k visits a year and many of them are from IE 6 and 7, because they come from countries where maybe internet is not so powerful or resources doesn't allow more recent machines/systems etc. I'm not sure how to tackle this issue, as there too many different opinions of the same subject. – user2881726 Apr 10 '14 at 15:09
  • Having said all that, for now @BoltClock answered my question. I'll keep looking for a better solution though. Thanks for your help anyway. – user2881726 Apr 10 '14 at 15:10

1 Answers1

1

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.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356