【问题标题】:IE specific css in CSS fileCSS 文件中的 IE 特定 css
【发布时间】:2014-06-22 21:45:11
【问题描述】:

我想将特定的 css 添加到 css 文件中。

.center{
margin-top:-40px !important;
}

我尝试添加

 .ie .center{
    margin-top:-40px !important;
    }

但是这个解决方案不起作用。有没有办法做到这一点。

【问题讨论】:

标签: css internet-explorer


【解决方案1】:

您需要编写html IF条件来检查客户端的浏览器是否为IE

<!--[if IE]> <link rel="stylesheet" type="text/css" href="ie.css" /> <![endif]-->

您知道它会查找所有版本的 Internet Explorer。无论如何我不建议使用这种方法,最好为所有浏览器创建一个 css 文件。

【讨论】:

    【解决方案2】:

    您可以只制作外部样式表来定位特定版本的 IE(或全部):http://css-tricks.com/how-to-create-an-ie-only-stylesheet/

    或者您可以针对特定 IE 版本使用 css hack:http://css-tricks.com/snippets/css/browser-specific-hacks/

    或者更好,每个人都有一个样式表(最佳解决方案)

    【讨论】:

      【解决方案3】:

      使用这个。你可以在你的正常风格中使用它。不需要为 IE 制作其他 css 文件。

      .center{
          margin-top:-40px;   /* IE9 and below */
          margin-top:-40px\9; /* IE8 and below */
          *margin-top:-40px;  /* IE7 and below */
          _margin-top:-40px;  /* IE6 */
      }
      

      【讨论】:

      • 我也需要ie10的特定css
      【解决方案4】:

      在我发布答案之前,我查看了发布的其他答案并看到了您的评论

      " 我还需要 ie10 的特定 css"

      所以我现在必须告诉你 Conditional Comments(这就是那些特定于 IE 的 css 应用程序的名称)在 IE10 和更高版本中被禁用,因为在他们看来,自从 IE10 以来,他们修复了大部分错误并且有不再需要它们了。

      【讨论】:

        【解决方案5】:

        在你的 head 标签中添加这个

        <!--[if IE]>
        <link rel="stylesheet" type="text/css" href="ie.css" class="ie" />
        <![endif]-->
        

        然后将你的css粘贴到ie.css中

        .ie .center{
            margin-top:-40px !important;
        }
        

        如果您想针对特定版本的 IE,例如

        <!--[if IE]>
            <link rel="stylesheet" type="text/css" href="ie10.css" class="ie10" />
        <![endif]-->
        

        您在 ie10.css 中的相应 css 将是

        .ie10 .center{
                margin-top:-40px !important;
        }
        

        获取更多 IE 特定 hack herehere

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-01-15
          • 2014-06-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-09-22
          • 1970-01-01
          • 2012-07-11
          相关资源
          最近更新 更多