只需要ie9的黑客攻击

时间:2012-09-06 09:07:43

标签: css internet-explorer-9 css-hack

是否只有针对IE9的黑客攻击?我只在IE9中遇到问题,其他浏览器工作正常。我正在使用\9,但它也影响了IE8。

我不想使用条件评论。

4 个答案:

答案 0 :(得分:21)

您可以使用此:root #element { color:pink \0/IE9; } /* IE9 + IE10pp4 */

答案 1 :(得分: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与其他浏览器。

答案 2 :(得分:5)

还有另一种方式!

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

使用:root伪相选择器。这是有效的,因为在IE9中删除了@media all and (min-width:0)部分以支持此方法。

请注意,这不是一种安全的方法,因为它不适用于所有选择器。最好的方法是条件注释,它是目标不同版本的Internet Explorer最安全,最简单和最好的方法,除了IE10,它已经放弃了对条件注释的支持。

答案 3 :(得分:0)

In my IE9 EMULATOR none of the solutions listed worked. The only hack that properly enabled us to resize, for example, a checkbox in IE9 was:

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

I don't know if this also affects IE8 or IE10 etc but we have conditionals handing those separately anyway.

Hopefully this helps someone.

相关问题