CSS 只需要对 ie9 进行 hack

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12296628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:06:20  来源:igfitidea点击:

Need hack for ie9 only

cssinternet-explorer-9css-hack

提问by supersaiyan

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.

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

I don't want to use conditional comments.

我不想使用条件注释。

回答by sandeep

You can use this :root #element { color:pink \0/IE9; } /* IE9 + IE10pp4 */

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

回答by Jeff Clayton

I came up with a media query that does this as well. It specifies only IE9.

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

@media all and (min-width:0
:root #div { background: #fff 
/* IE9 */
:root input#my-checkbox {
    width:20px !important \ ;
    height:20px !important \ ;
    box-sizing:content-box !important \ ;
}
/IE9; } /* IE9 */
) and (min-resolution:.001dpcm) { #div { color:red; } }

Other ones I have worked out, including a msie 9+ media query are on my github page: https://github.com/jeffclayton/css_hack_testing- most of these I have sent to browserhacks.com for inclusion.

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

2017 UPDATE: To see it working, I created a live test page here for this and many others I worked on http://browserstrangeness.bitbucket.io/css_hacks.htmland MIRROR: http://browserstrangeness.github.io/css_hacks.html

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

Please be aware it is min-width:0\0 (zero-backslash-zero) when you copy the code to your own site. Not to be confused with min-width:0 (just a single zero) which does not work to differentiate IE9 from other browsers.

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

回答by Kyle

There is another way!

还有一种方法!

##代码##

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

使用:root伪选择器。这是有效的,因为@media all and (min-width:0)在 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.

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

回答by cbmtrx

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 模拟器中,列出的所有解决方案都不起作用。例如,唯一能让我们调整大小的 hack 是 IE9 中的复选框:

##代码##

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

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

Hopefully this helps someone.

希望这有助于某人。