【问题标题】:Conditional Comments not working on IE-9条件注释不适用于 IE-9
【发布时间】:2013-01-01 12:57:29
【问题描述】:

我有一个页面,我需要根据 IE 的版本显示帮助文本。我决定按照this blog 使用条件 cmets。我的html页面是这样的...

<!DOCTYPE html>
<html>
   <head>
        <title>Application Title</title>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    </head>
  <!--[if lt IE 9 ]><body style="margin: 0px;" class="ie9lt"><![endif]-->
  <!--[if IE]> <body style="margin: 0px;" class="ie9"> <![endif]-->
  <!--[if (gt IE 10)|!(IE)]>-->
  <body style="margin: 0px;"><!--<![endif]-->
        <div id="id1">
        ....
        ....
</html>

我已经在 IE 9 上打开了这个文件,但是通过检查元素选项检查了 html,但是我的 body 元素没有与之关联的 ie9 类(就此而言没有类)。我在这里错过了什么吗?请帮忙

【问题讨论】:

  • IE 10 绝对不支持条件 cmets,因此 (gt IE 10) 不会做太多事情。好在它是默认条件。

标签: html internet-explorer internet-explorer-9 conditional-statements


【解决方案1】:

我只会将样式定义放在那些 cmets 中,没有别的。让 html 文档尽可能保持干净。这可能是该 hack 最混乱的实现之一。

【讨论】:

    【解决方案2】:

    我已经用 IE9 检查了你的 HTML,它运行良好。我可以看到bodyie9 类。

    你能在下面的 HTML 检查器中看到相同的内容吗?另外,您的浏览器模式是否设置为 IE9?

    有时,当您的 HTML 文档出现错误时,IE 会自动切换到 兼容性视图 模式,然后您的 body 类是 ie9lt(而不是 ie9)。

    【讨论】:

      【解决方案3】:

      您可以尝试更具体地处理根 HTML 标记:

      <!doctype html>
      <!--[if IE 7 ]><html lang="en" class="ie7"><![endif]-->
      <!--[if IE 8 ]><html lang="en" class="ie8"><![endif]-->
      <!--[if IE 9 ]><html lang="en" class="ie9"><![endif]-->
      <!--[if (gt IE 9)|!(IE)]><!-->
      <html lang="en">
      <!--<![endif]-->
      

      【讨论】:

        猜你喜欢
        • 2016-07-22
        • 2011-01-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-22
        • 1970-01-01
        • 2014-04-02
        • 2013-10-08
        相关资源
        最近更新 更多