css - !important 或 !notimportant 在 IE6 和 7 中?

标签 css internet-explorer

我的一个 friend 说,无论您在层叠样式表中的 ! 键后使用什么单词,它仍然会增加额外的重量,只要它是 Internet Explorer 6或 7。

这意味着我可以写 !notimportant 并且它仍然会被认为是重要的。我对此主题的问题是:这是真的吗?

我无法自己尝试,因为我没有任何 Windows 计算机(不在工作或家里)。不过,了解一下会很有趣。

提前致谢。

最佳答案

这是正确的。 IE6/IE7 错误地将 ! 后跟任何标识符和空格视为 !important 标记,而不是完全忽略该声明。一些引用资料:

规范规定 ! 后面只能跟不区分大小写的 important ,并用可选的空格和注释分隔它们,以便将其识别为重要声明。您可以在 grammar 中看到这一点:

"!"({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 及更高版本将正确忽略它们,尽管这可能会也可能不会在兼容性 View 中的这些版本中重现。

请注意,虽然 Jigsaw W3C CSS Validator!/**/important 报告为无效(! 后紧跟注释而不是空格),这是验证器解析器的错误。根据语法它肯定是有效的。

关于css - !important 或 !notimportant 在 IE6 和 7 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13489438/

相关文章:

css - JavaFX css 边界半径问题

css - 删除 Stack Exchange 链接的下划线样式而不闪烁

session - 如何停止与多个 Edge 浏览器共享 session

javascript - 表单重置后,js checkValidity() 不再正常运行

css - 即 : How to get :active to also work on parent element (CSS-only)

css - 热链接我的级联样式表

css - 如何使用CSS制作关键形状?

javascript - 在外部单击时关闭选项卡

javascript - IE : window. 打开超过2083个字符的url

javascript - 在 IE11 中循环