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

标签 css internet-explorer cross-browser browser-detection

<分区>

我一直在寻找解决我遇到的 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/

相关文章:

javascript - HTML页面打印

javascript - 如何禁用浏览器中的 'Open Link in New Tab'?

html - 将表格基础设计转换为无表格设计的工具

jquery - 与 Chrome 和 fullPage.js 冲突

javascript - CSS 过渡速度根据鼠标位置变化

javascript - 将 CSS 与 React/JSX 结合使用

javascript - 如何使用javascript从IE中的iframe中删除边框

javascript - IE 的 contenteditable 模式下的图像调整大小句柄

internet-explorer - 如何修改 IE Gradient CSS 以使用高度和第三种颜色?

css - 跨浏览器自定义光标样式