What is the scope of the * CSS hack?

拥有回忆 提交于 2019-12-30 09:53:06

问题


I have been looking at a hack to solve a CSS problem I have. I haved 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?


回答1:


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.



来源:https://stackoverflow.com/questions/645865/what-is-the-scope-of-the-css-hack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!