为什么样式表加载时Contional注释内容指出应该忽略它? [英] Why is Stylesheet loaded when Contional Comment states it should be ignored?

查看:392
本文介绍了为什么样式表加载时Contional注释内容指出应该忽略它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有条件的意见将指示浏览器忽略的内容,如果条件不满足?!

I thought conditional comments would instruct the browser to ignore the content if the condition is not met?!

例如我想只包括一个样式表,如果是IE6浏览器。 HEAD>在位于在&lt以下;页面的元素

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]-->

<!--[if IE 6]>
  <link rel="Stylesheet" type="text/css" href="../css/IE6.css" />
<![endif]-->

为什么IE7,IE8和FF3所有负载的样式表?!

How come IE7, IE8 and FF3 all load that stylesheet?!

注:更改条件[如果LTE IE 6]没有任何区别! (

NOTE: Changing the condition to [if lte IE 6] does not make any difference! :(

重大更新

我是一个白痴......我只注意到我做错了什么!
我已经给出的例子稍微修改。下App_Themes文件的CSS文件的路径!当然,CSS总是装!

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!!!

推荐答案

尝试:

<!--[if lte IE 6]>
   <link id="IE6StyleSheet" rel="Stylesheet" type="text/css" href="../css/IE6.css" />
<![endif]-->

这只会加载IE6或更低版本的样式表。下面是你可以使用测试脚本,它可以打印出你正在使用的IE版本:

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>

您不应该看到在Firefox任何文本与这个测试code。

You should not see any text in Firefox with this test code.

这篇关于为什么样式表加载时Contional注释内容指出应该忽略它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆