【问题标题】:Apply css styles only to ie9仅将 css 样式应用于 ie9
【发布时间】:2013-02-07 17:44:34
【问题描述】:

我的网站我有一个文件 (ie.css) 来纠正 ie 的 css 问题。 但是,现在我有一个小问题。网站的一些默认样式在ie8上很好,在ie9上不行。

所以,我想将文件“ie.css”中的以下css代码仅应用于ie版本9,这可能吗?

.ngg-galleryoverview {
    overflow: hidden;
    margin-top: 10px;
    width: 100%;
    clear:both; 
    display:block !important;
    /*border: 2px solid #ADE132;*/
    /*margin-left: 10px;*/
    margin-left: 2%;
}

.ngg-gallery-thumbnail {
    float: left;
    margin-right: 3%;
    /*margin-right: 10px;*/
    text-align: center;
    /*border: 2px solid #ADE132; */
    height: 430%;
    width: 430%;
}

【问题讨论】:

标签: html internet-explorer css


【解决方案1】:

您正在寻找的是条件 cmets:

<!--[if IE 9]>
<style type="text/css">
  IE specific CSS rules go here
</style>
<![endif]-->

【讨论】:

    【解决方案2】:

    最好的方法是只为 IE9 设置一个 body 类,当你想修改你的 css 时,它将在任何其他 html 标记或类前面开始该类。这将保证您的 css 符合 w3c。

    代码如下:

    <!--[if IE 9 ]>    <body class="ie9"> <![endif]-->
    

    【讨论】:

    • 如果你将它应用到 html 标签上你会遇到 windows phone 的问题,IE 不喜欢在 标签中看到任何东西。我测试了自己,所以最好的选择是在 标签上使用它。
    • 这可能是更好的方法之一。它不需要像加载额外的 CSS 文件那样额外的 HTTP 请求。
    【解决方案3】:

    使用 IE 条件 cmets:

    <!-- [if ie 9]>
     CSS that you want to be IE only
    <![endif]>-->
    

    【讨论】:

    • 我必须创建一个特定的文件来解决这个问题?或者我可以在我的 ie.css 文件中使用这些标签?
    • 您可以在 if 语句中包含指向您的 ie.css 的链接。或者,正如其他人所说,您可以走不同的路线并更改您的 HTML 类,如下所示:paulirish.com/2008/…
    【解决方案4】:

    在css中试试

    :root .classname{ 颜色:粉色 \0/IE9; } /* IE9 */

    或 写入head标签

    
    

    【讨论】:

    • 我建议使用条件 CSS 规则
    猜你喜欢
    • 1970-01-01
    • 2012-08-03
    • 2016-02-11
    • 2012-05-27
    • 2015-12-16
    • 2018-12-18
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    相关资源
    最近更新 更多