I thought conditional comments would instruct the browser to ignore the content if the condition is not met?!
For example I want to only include a stylesheet if IE6 is the browser. The following in located in the <HEAD> element of the page.
<!--[if IE 6]>
<link id="IE6StyleSheet" rel="Stylesheet" type="text/css" href="~/css/IE6.css" runat="server" />
<![endif]-->
or
<!--[if IE 6]>
<link rel="Stylesheet" type="text/css" href="../css/IE6.css" />
<![endif]-->
How come IE7, IE8 and FF3 all load that stylesheet?!
NOTE: Changing the condition to [if lte IE 6] does not make any difference! :(
MAJOR UPDATE
I am a moron... I just noticed what I did wrong! The example I'd given was slightly modified. The path to the css file in under App_Themes! Of course the css was always loaded!!!
Try:
<!--[if lte IE 6]>
<link id="IE6StyleSheet" rel="Stylesheet" type="text/css" href="../css/IE6.css" />
<![endif]-->
This will only load the stylesheet for IE6 or lower versions. Here's a test script you can use, it will print out which version of IE you're using:
<p><!--[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]-->
</p>
You should not see any text in Firefox with this test code.
来源:https://stackoverflow.com/questions/795267/why-is-stylesheet-loaded-when-contional-comment-states-it-should-be-ignored