<分区>
我一直在寻找解决我遇到的 CSS 问题的技巧。我已经使用一个为 Internet Explorer 创建自定义规则。
margin-top:45px;
*margin-top:0px;
这个 hack 是否适用于所有 IE 浏览器?此 hack 是否出现在任何版本的 Firefox 或 Safari 中?
<分区>
我一直在寻找解决我遇到的 CSS 问题的技巧。我已经使用一个为 Internet Explorer 创建自定义规则。
margin-top:45px;
*margin-top:0px;
这个 hack 是否适用于所有 IE 浏览器?此 hack 是否出现在任何版本的 Firefox 或 Safari 中?
最佳答案
这适用于 IE7 及以下版本。但请注意,这不是有效的 CSS,它随时可能崩溃。参见 here有关各种 CSS 黑客及其影响的浏览器的更全面列表。
Although Internet Explorer 7 corrected its behavior when a property name is prefixed with an underscore or a hyphen, other non-alphanumeric character prefixes are treated as they were in IE6. Therefore, if you add a non-alphanumeric character such as an asterisk (*) immediately before a property name, the property will be applied in IE and not in other browsers. Unlike with the hyphen and underscore method, the CSS specification makes no reservations for the asterisk as a prefix, so use of this hack could result in unexpected behavior as the CSS specifications evolve.
我强烈建议您重新考虑您是否真的需要这种 hack,以及是否有更好的方法来完成您想要的事情。
关于css - * CSS hack 适用于哪些浏览器和版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/645865/