IE Conditional Comment

When develop a website, you should take care of anything that IE can throw at you without the use of hacks. Hacks are dangerous, since they are based on non-standard exploits and you can’t trust how they’re going to behave on the future browsers. Thus the solution for this problem is the conditional stylesheet or conditional comment. One important thing is that IE 10 and up don’t support conditional comment

Conditional comment operators

Operator Description
IE represents Internet Explorer; if a number value is also
specified, it represents a version vector
lt less than operator
lte less than or equal to
gt greater than
gte greater than or equal to
! the NOT operator
() subexpression operator
& the AND operator
| the OR operator
true evaluates to true
false evaluates to false

Syntax

Target everything except IE

<!--[if !IE]>
  <link rel="stylesheet" type="text/css" href="not-ie.css" />
<![endif]-->

Target IE7 only

<!--[if IE 7]>
  <link rel="stylesheet" type="text/css" href="ie7.css" />
<![endif]-->

Target IE8 and lower

<!--[if lte IE 8]>
  <link rel="stylesheet" type="text/css" href="ie8.css" />
<![endif]-->

These conditional comments don’t have to be used only for CSS. You could load JavaScript, or even use them to display the specific content of your site.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s