* CSS hack 适用于哪些浏览器和版本?

发布于 2024-07-15 06:00:06 字数 205 浏览 14 评论 0原文

我一直在寻找一种 hack 来解决我遇到的 CSS 问题。 我已使用其中一个为 Internet Explorer 创建自定义规则。

margin-top:45px;
*margin-top:0px;

这个 hack 是否适用于所有 IE 浏览器? 此黑客攻击是否出现在任何版本的 Firefox 或 Safari 中?

I have been looking at a hack to solve a CSS problem I have. I have used one to create a custom rule for Internet Explorer.

margin-top:45px;
*margin-top:0px;

Does this hack apply to all IE browsers? Does this hack appear in any versions of Firefox or Safari?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉黛浅 2024-07-22 06:00:06

这适用于 IE7 及以下版本。 但请注意,这不是有效的 CSS,并且它随时可能会崩溃。 有关各种 CSS 黑客攻击及其影响的浏览器的更全面列表,请参阅此处

尽管 Internet Explorer 7 更正了属性名称以下划线或连字符作为前缀时的行为,但其他非字母数字字符前缀的处理方式与 IE6 中相同。 因此,如果您在属性名称前添加非字母数字字符,例如星号 (*),则该属性将应用于 IE,而不是其他浏览器。 与连字符和下划线方法不同,CSS 规范没有保留星号作为前缀,因此随着 CSS 规范的发展,使用此 hack 可能会导致意外行为。

我强烈建议您重新考虑您是否真的需要这种技巧,以及是否没有更好的方法来完成您想要的事情。

This applies to IE7 and below. But be aware that this is not valid CSS, and it could break at any time. See here for a more comprehensive list of the various CSS hacks and which browsers they affect.

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.

I'd strongly recommend reconsidering whether you really need this hack, and if there isn't a better way to do what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文