Roberto Flores
Roberto Flores

Reputation: 789

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

Upvotes: 0

Views: 139

Answers (1)

Andrew Myers
Andrew Myers

Reputation: 2786

<!--[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.

Upvotes: 2

Related Questions