-1

I am a newbie to UI. I see the conditional comments used to identify the IE browser like

<!--[if IE 10]> <html class="no-js ie10" lang="en"> <![endif]-->
<!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]-->

They work fine but can anyone explain how it works? Doesn't IE recognize these statements as comments?

sushmita
  • 1
  • 3
  • I found this link http://reference.sitepoint.com/css/conditionalcomments. It has helped me understand the basics of conditional comments. Thought of sharing it here. – sushmita Feb 07 '14 at 02:48

2 Answers2

1

First of all, IE10 does not have Conditional Comments Recognition, it has been disabled, it works only for IE9 and lower. Versions over 10 are much less buggy than the earlier ones. This is how this works:

<!--[if lte IE8]>
  <style type="text/css">
    IE lower or equal to 8 CSS rules go here
  </style>
<![endif]-->

An entire stylesheet

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

lower and equal to IE7

<!--[if lte IE7]>

lower than IE7

<!--[if lt IE7]>

greater than IE7

<!--[if gt IE7]>

not IE7

<!--[if !IE7]>

IE7

<!--[if IE7]>

Conditional comments do not work within stylesheets. But, you can use conditional comments in your HTML to apply different CSS classes or IDs to elements that you can then target with CSS.

Works something like this:

<!--[if IE7]>
  <div id="content" class="ie7">
<![endif]-->
<!--[if !IE7]>
  <div id="content">
<![endif]-->
Kevin B
  • 92,700
  • 15
  • 158
  • 170
0

These are just conditional statements that are read by internet explorer, and allow web devs to get around the plethora of issues developing for IE brings.

Ironically, IE10 and above drops support for these entirely so they are really only useful for retro coding for old browsers, i,.e when using HTML5 shivs such as

<!--[if lt IE 9]>
<script src="dist/html5shiv.js"></script>
<![endif]-->

How do they work.. IE (below 10) just detects them as part of its rendering engine, and other browsers just treat as comments

Here some info about them being removed, and a link to other resources if you want to look more into it, or get better examples

http://www.therailsview.com/2012/02/internet-explorer-10-to-no-longer-support-conditional-comments/
MOLEDesign
  • 478
  • 6
  • 19