【问题标题】:!important or !notimportant in IE6 and 7?!important 还是 !notimportant 在 IE6 和 7 中?
【发布时间】:2012-11-09 11:29:02
【问题描述】:

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

这意味着我可以写!notimportant,它仍然被认为是重要的。我对这个线程的问题是:这是真的吗?

我不能自己尝试,因为我没有任何 Windows 机器(不在工作或家中)。不过知道会很有趣。

提前致谢。

【问题讨论】:

  • 为什么你在发布这个问题之前没有自己尝试?
  • @Bondye:你读过这个问题吗? OP 已经解释了原因。
  • 因为我无法访问任何 Internet Explorer。如果您阅读该主题,您会注意到。
  • 是的,我做到了,他不能尝试,但他只是不知道如何尝试
  • 只是一个旁注,这是合乎逻辑的,因为 !!important = 重要(双重否定)。 !important = 重要(无效否定?)是不合逻辑的

标签: css internet-explorer


【解决方案1】:

没错。 IE6/IE7 错误地将! 后跟任何标识符和空格视为!important 令牌,而不是完全忽略声明。一些参考资料:

规范声明! 后面只能跟不区分大小写的important,并带有可选的空格和 cmets 将它们分开,以便将其识别为重要声明。你可以在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 及更高版本将正确忽略它们,尽管这可能会或可能不会在兼容性视图中的这些版本中重现。

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

【讨论】:

  • @Damien Overeem:公平地说,这至少是六年前的 IE。最近情况好多了,尽管有些事情永远不会改变,这是可以理解的。
  • 他们确实尝试过.. 但该死的,他们花了很长时间才摆脱困境并开始遵守大多数其他人已经使用的标准... 示例:让我们构建 microsoft silverlight ,大约 2 年之后,每个人都放弃了 html5 的 Flash ;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多