-1

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!

Luca Putzu
  • 1,408
  • 18
  • 24
joacoleza
  • 695
  • 1
  • 9
  • 24
  • Confusing. Do you have two completely separate and fully self-contained stylesheets you want to switch between? I used to (before dropping old IE) have a main stylesheet which was served to everything, and then conditional IE8 and IE9 sheets which went over the top and fixed specific issues. – Starscream1984 Mar 17 '16 at 14:39
  • Note that conditional comments are for IE only, not other browsers, and do not work on IE >9 – Rob Mar 17 '16 at 15:09

2 Answers2

1

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]-->
BoltClock
  • 630,065
  • 150
  • 1,295
  • 1,284
0

Just put your styles before IE conditionals

<link rel="stylesheet" type="text/css" href="your_styles.css">

<!--[if lt IE 9]>
  This is less then IE9
<![endif]-->
<!--[if gt IE 8]>
  this is for: IE9 or higher
<![endif]-->
Bart
  • 1,168
  • 2
  • 11
  • 13
  • yes, but the thing is that if the browser is ie8 or lower I don't want to use that styles – joacoleza Mar 17 '16 at 14:38
  • in IE css files you need to have only styles for particular version of IE, for some specific elements of your website which IE do not "understand in normal way" :) , and that styles should overwrite styles in your main css file – Bart Mar 17 '16 at 14:47
  • yes, I get that is the "good practice" way. But this was a really specific problem to make something compatible with ie8. The BoltClock answer solve my problem. Thanks for the comments! – joacoleza Mar 17 '16 at 15:53