【问题标题】:How is `outline: inherit 0` interpreted?`outline:inherit 0` 是如何解释的?
【发布时间】:2014-03-15 14:40:59
【问题描述】:

According to w3schoolsoutline 的语法是:
outline: <color> <style> <width>;,这三个都可以省略。

inherit 的值是三个的有效值,或者单个outline: inherit 意味着它应该继承所有三个。

我问这个是因为我正在为 CSS 缩小器开发属性优化器。根据上面的链接,
outline: inherit none 3px相当于outline: inherit 3px
outline: invert inherit 3px也相当于outline: inherit 3px
但结果似乎太模棱两可了。

所以问题是,浏览器如何解释outline: inherit 0px?他们是否将inherit 分配给颜色或样式?

【问题讨论】:

  • 请不要将“根据 W3C”链接到 w3schools.com ever - 因为:w3fools.com。至于问题本身:你自己在不同浏览器中测试的结果是什么?
  • @CBroe 我完全同意你的看法,特别是因为你可以看到人们开始混淆万维网联盟 (W3C) 和这个第三方网站。
  • 别在意 W3C 和 W3Schools 之间的混淆 - W3Schools 甚至在哪里说“inherit 的值是三个的有效值”?
  • 抱歉,我的印象是 w3schools 与 W3C 有某种关联。

标签: css web-standards css-parsing


【解决方案1】:

它被忽略了。这是当前的浏览器实践和 CSS 中的预期原则:对于像 outline 这样的简写符号,允许将关键字 inherit 作为值(使所有子属性继承),但不能与任何其他值结合使用。原因很明显:否则该值不会有明确的解释。在inherit 0的值中,0的值只能是outline-width的值,而inherit可以是outline-styleoutline-color的值。

CSS 2.1 规范的附录中提到了该原理,地址为C.3.1。理论上,附录 C 是对变化的信息性描述,而不是规范性的,在这里它并不反映实际的变化。也就是说,这是搞砸了:描述了意图,但通常 CSS 2.1 没有这个原则,并且会认为 outline: inherit 0 是有效的(但 W3C CSS Validator 拒绝它)。参照。到Is this font: shorthand property syntax valid? (My reading of the spec says yes, but half of my installed browsers disagree.)(处理与font 速记有关的相同问题)。

如果您希望所有 outline 属性都被继承但宽度设置为零(这有点奇怪),您需要两个声明

outline: inherit;
outline-width: 0;

【讨论】:

  • 感谢 Jukka 的回答,我不知道 inherit 不能在速记声明中使用。
【解决方案2】:

需要注意的是,w3schools 对 order 的定义并不完整。以下都是有效的

outline: <color> <style> <width>
outline: <color> <width> <style> 


outline: <width> <style> <color>
outline: <width> <color> <style>


outline: <style> <width> <color>
outline: <style> <color> <width>

因为顺序无关紧要。这反过来又成为outline: inherit none 3px 无效的原因,因为3px 也可以表示color

outline: inherit 0px 同样等同于outline: inherit initial 0px,因此可以引用outline-color: 0px

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 2012-12-10
    • 2011-08-12
    • 2021-02-07
    • 2018-07-24
    • 1970-01-01
    相关资源
    最近更新 更多