代码之家  ›  专栏  ›  技术社区  ›  BlackMael

为什么样式表加载时,连续的评论指出它应该被忽略?

  •  1
  • BlackMael  · 技术社区  · 17 年前

    我以为如果条件不满足,有条件的评论会指示浏览器忽略内容?!

    例如,如果IE6是浏览器,我只想包含一个样式表。位于<头部>页面的元素。

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

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

    重大更新

    我举的例子稍加修改。在App\u主题下的css文件的路径!当然css总是被加载的!!!

    1 回复  |  直到 17 年前
        1
  •  2
  •   John Rasch    17 年前

    尝试:

    <!--[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中看到带有此测试代码的任何文本。