Ms0*_*s01 2 css internet-explorer
我的一位朋友说,!
在层叠样式表中使用密钥之后使用哪个单词并不重要,只要它是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;}
Run Code Online (Sandbox Code Playgroud)
所以虽然这些是有效的重要声明:
background: transparent !important;
background: transparent !IMPORTANT;
background: transparent !ImPoRtAnT;
background: transparent ! important;
background: transparent ! important;
background: transparent ! /**/important;
background: transparent ! /**/ /**/ important;
background: transparent !/**/important;
Run Code Online (Sandbox Code Playgroud)
这些都是无效的,应该被忽略(甚至不尝试应用背景):
background: transparent !notimportant;
background: transparent !NOTIMPORTANT;
background: transparent !NoTiMpOrTaNt;
background: transparent ! notimportant;
background: transparent ! notimportant;
background: transparent !ie7;
background: transparent !abc;
background: transparent !_;
Run Code Online (Sandbox Code Playgroud)
但是IE6/7将把它们都像有效的!important
报表和应用背景.IE8及更高版本将正确地忽略它们,尽管在兼容性视图中这些版本可能会或可能不会重现.
请注意,虽然Jigsaw W3C CSS Validator报告!/**/important
为无效(!
紧接着是注释而不是空格),但这是验证器解析器的错误.根据语法,它绝对有效.