我的一个朋友说,!
在层叠样式表中的键之后使用什么词并不重要,它仍然会增加额外的重量,只要它是 Internet Explorer 6 或 7。
这意味着我可以写作!notimportant
并且它仍然被认为是重要的。我对这个线程的问题是:这是真的吗?
我不能自己尝试,因为我没有任何 Windows 机器(不在工作或家里)。不过知道会很有趣。
提前致谢。
我的一个朋友说,!
在层叠样式表中的键之后使用什么词并不重要,它仍然会增加额外的重量,只要它是 Internet Explorer 6 或 7。
这意味着我可以写作!notimportant
并且它仍然被认为是重要的。我对这个线程的问题是:这是真的吗?
我不能自己尝试,因为我没有任何 Windows 机器(不在工作或家里)。不过知道会很有趣。
提前致谢。
那是对的。IE6/IE7 错误地将!
后跟任何标识符和空格视为!important
标记,而不是完全忽略声明。一些参考资料:
!ie7
在这个网站上有一个例子以及指向上述参考的链接)规范声明!
只能在不区分大小写的情况下important
使用可选的空格和将它们分开的注释,以便将其识别为重要声明。您可以在语法中看到这一点:
"!"({w}|{comment})*{I}{M}{P}{O}{R}{T}{A}{N}{T} {return IMPORTANT_SYM;}
因此,虽然这些是有效的重要声明:
background: transparent !important;
background: transparent !IMPORTANT;
background: transparent !ImPoRtAnT;
background: transparent ! important;
background: transparent ! important;
background: transparent ! /**/important;
background: transparent ! /**/ /**/ important;
background: transparent !/**/important;
这些是无效的,应该被忽略(甚至不要尝试应用背景):
background: transparent !notimportant;
background: transparent !NOTIMPORTANT;
background: transparent !NoTiMpOrTaNt;
background: transparent ! notimportant;
background: transparent ! notimportant;
background: transparent !ie7;
background: transparent !abc;
background: transparent !_;
但是 IE6/7 会将它们都视为有效!important
语句并应用背景。IE8 及更高版本将正确忽略它们,尽管在兼容性视图中的这些版本中可能会或可能不会重现。
请注意,虽然Jigsaw W3C CSS Validator报告!/**/important
为无效(!
紧接着是注释而不是空格),但这是验证器解析器的错误。根据语法,它肯定是有效的。