htmlcssinternet-explorerconditional-comments

Else in html conditional for ie


I want to load a .css file if the browser is ie8 or lower and other file if the browser is greater than ie8 or other browser (chrome, safari, etc).

I've read that ther isn't an else in html conditional. And the answers here always says to use something like this:

<!--[if lt IE 9]>
  This is less then IE9
<![endif]-->
<!--[if gt IE 8]> <!-- -->
  this is all browsers: IE9 or higher, firefox, chrome, etc.
<!-- <![endif]-->

The problem with this is that I don't want to do that only if the browser is greater than 8, I want to do iy if the browser is other than ie also.

How can I do it?

Thanks!


Solution

  • The <!-- --> will ensure that other browsers see the content between it and the next <!--. Notice how the syntax highlighter on Stack Overflow does not highlight the content as an HTML comment — that's how you can tell.

    A more common variation that's somewhat shorter:

    <!--[if gt IE 8]><!-->
      this is all browsers: IE9 or higher, firefox, chrome, etc.
    <!--<![endif]-->