我认为如果条件不满足,条件评论会指示浏览器忽略内容?!
例如,如果IE6是浏览器,我想只包含一个样式表。以下位于< HEAD>页面的元素。
<!--[if IE 6]>
<link id="IE6StyleSheet" rel="Stylesheet" type="text/css" href="~/css/IE6.css" runat="server" />
<![endif]-->
或
<!--[if IE 6]>
<link rel="Stylesheet" type="text/css" href="../css/IE6.css" />
<![endif]-->
为什么IE7,IE8和FF3都加载了样式表?!
注意:将条件更改为[if lte IE 6]没有任何区别! :(
主要更新
我是个白痴......我只是注意到我做错了什么! 我给出的例子略有修改。 App_Themes下的css文件路径!当然css总是加载!!!
答案 0 :(得分:2)
尝试:
<!--[if lte IE 6]>
<link id="IE6StyleSheet" rel="Stylesheet" type="text/css" href="../css/IE6.css" />
<![endif]-->
这只会加载IE6或更低版本的样式表。这是您可以使用的测试脚本,它将打印出您正在使用的IE版本:
<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>
使用此测试代码,您不应在Firefox中看到任何文本。