10

Is there a hack to target IE9 only? I am facing a problem in IE9 only, other browsers are working fine. I am using \9, but it is effecting IE8 as well.

I don't want to use conditional comments.

4

4 回答 4

21

你可以用这个:root #element { color:pink \0/IE9; } /* IE9 + IE10pp4 */

于 2012-09-06T09:10:14.733 回答
15

我想出了一个媒体查询也可以做到这一点。它仅指定 IE9。

@media all and (min-width:0\0) and (min-resolution:.001dpcm)
{
    #div { color:red; }
}

我已经解决的其他问题,包括 msie 9+ 媒体查询在我的 github 页面上:https ://github.com/jeffclayton/css_hack_testing - 其中大部分我已发送到 browserhacks.com 以供包含。

2017 更新:为了看到它的工作,我在这里创建了一个实时测试页面,以及我在http://browserstrangeness.bitbucket.io/css_hacks.html和 MIRROR 上工作的许多其他页面:http: //browserstrangeness.github.io/css_hacks .html

请注意,当您将代码复制到自己的站点时,它是 min-width:0\0(零反斜杠零)。不要与 min-width:0 (只是一个零)混淆,它不能将 IE9 与其他浏览器区分开来。

于 2014-05-27T03:51:39.143 回答
5

There is another way!

:root #div { background: #fff \0/IE9; }  /* IE9 */

Use the :root psuedo selector. This works because the @media all and (min-width:0) part as been removed in favor of this method in IE9.

Be aware though, that this is not a safe method as it doesn't work on all selectors. The best thing to use is conditional comments, it is the safest, easiest and best way to target different versions of Internet Explorer except IE10 which has dropped the support for conditional comments.

于 2012-09-06T09:10:44.010 回答
0

在我的 IE9 模拟器中,列出的解决方案都不起作用。唯一能让我们正确调整大小的技巧,例如,IE9 中的复选框是:

/* IE9 */
:root input#my-checkbox {
    width:20px !important \ ;
    height:20px !important \ ;
    box-sizing:content-box !important \ ;
}

不知道这是否也会影响 IE8 或 IE10 等,但无论如何我们都有条件单独处理这些。

希望这可以帮助某人。

于 2015-06-15T15:16:33.850 回答