How to use style definitions specifically for specific MSIE versions Using Conditional Comments.

“Conditional Comments” (CC) are most commonly used to differentiating Cascading Style Sheets (CSS) rules intended for specific versions of Internet Explorer. Conditional comments are proprietary conditional statements interpreted by Microsoft Internet Explorer. Conditional comments have been available since MSIE 5 Windows and later (Mac IE doesn’t support them.). The most beneficial aspect of conditional comments is that you are not trusting on browser bugs when using them.

How to write a conditional comment

The following conditional comment is being picked up by IE5, IE5.5 and IE6:

simply we define as:

Targeting IE5
If you need to target IE5 specifically, you do so by appending a version number:
<!–[if IE 5.0]>
<link rel=”stylesheet” type=”text/css” href=”style5.0.css” />
<![endif]–>
Targeting IE5.5
If you specifically need to target IE5.5, it’d look like this:
<!–[if IE 5.5]>
<link rel=”stylesheet” type=”text/css” href=”style5.5.css” />
<![endif]–>
Targeting IE6
The same goes for IE6:
<!–[if IE 6]>
<link rel=”stylesheet” type=”text/css” href=”style6.0.css” />
<![endif]–>

and we can right it in details as:

<!–[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]–>
<!–[if IE 5]>
According to the conditional comment this is Internet Explorer 5<br />
<![endif]–>
<!–[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0<br />
<![endif]–>
<!–[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5<br />
<![endif]–>
<!–[if IE 6]>
According to the conditional comment this is Internet Explorer 6<br />
<![endif]–>
<!–[if IE 7]>
According to the conditional comment this is Internet Explorer 7<br />
<![endif]–>
<!–[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up<br />
<![endif]–>
<!–[if lt IE 6]>
According to the conditional comment this is Internet Explorer lower than 6<br />
<![endif]–>
<!–[if lte IE 5.5]>
According to the conditional comment this is Internet Explorer lower or equal to 5.5<br />
<![endif]–>
<!–[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6<br />
<![endif]–>

We can any of these parameters in our conditional comment:

  • IE- Any version of IE
  • lte – less than or equal
  • lt – less than
  • gte – greater than or equal
  • gt – great than
  • (IE6)|(IE7) – if Internet Explorer 6 OR Internet Explorer 7
  • (IE6)&(IE7) – if Internet Explorer 6 AND Internet Explorer 7

cheers!!
Joginder Poswal

Tags: , ,

This entry was posted on Friday, May 8th, 2009 at 6:10 am and is filed under CSS, XHTML. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “How to use style definitions specifically for specific MSIE versions Using Conditional Comments.”

  1. subhash sharma Says:

    Thanks buddy. nice to see all this info

  2. jposwal Says:

    Thanks subhash.

Leave a Reply

Anti-Spam Protection by WP-SpamFree

Get Adobe Flash playerPlugin by wpburn.com wordpress themes