Roberto Flores Roberto Flores - 4 months ago 16
HTML Question

How do I target css styling to other browsers except for IE9

I am trying to target a particular styling for all browsers except for ie9 and below.

I did this to target IE9 and below:

<!--[if lte IE 9]>
<link rel="stylesheet" href="css/ie/ie.min.css">
<![endif]-->


I do not recall what would be the other way to target all other browsers except for IE9. I do recall there is a way to do it like I did to target IE9 and below but I do not recall.

Any help would be appreciated

Answer
<!--[if lt IE 9]>
   <link rel="stylesheet" href="css/ie/ie.min.css">
<![endif]-->
<!--[if IE 9]>
   <link rel="stylesheet" href="css/ie/ie-9.min.css">
<![endif]-->
<!--[if gt IE 9]><!-->
   <link rel="stylesheet" href="css/normal.min.css">
<!--<![endif]-->

This method should provide you with separate stylesheets for less than IE 9, IE 9, and more than IE 9 (including all non-IE browsers). The trick for the last conditional is <!--> and <!--<!, which cause Edge and non-IE browsers to interpret the if and endif as separate comments.

To target a single version in particular, use <!--[if IE #]>.

As pointed out by jkdev, since IE 9 is the last version to support conditional comments, the last conditional could have been written:

<!--[if !IE]><!-->
   <link rel="stylesheet" href="css/normal.min.css">
<!--<![endif]-->

The result would be the same as the first snippet: only IE 10-11, Edge, and non-IE browsers would get css/normal.min.css. None of the earlier IE versions would get this file since they would evaluate if !IE.

See also Conditional comments for Internet Explorer.

Comments