gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:22:24 25 4
gpt4 key购买 nike

我的一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com