为什么 CSS 接受 'grey' 但不接受 'colour'?
Why does CSS accept 'grey' but not 'colour'?
作为主要使用英式英语的人,CSS 不接受 colour
作为有效 属性 的事实相当令人讨厌,尤其是 当它接受 grey
(及其偏差)作为有效值时。为什么 CSS 允许在值中使用英式英语,而不是在属性中?
根据 W3 CSS color specification,官方 CSS color
值的拼写是 gray
:
然而,它也接受grey
(及其偏差)就好了:
.gray {
color: gray;
}
.grey {
color: grey;
}
<span class="gray">gray</span>
<span class="grey">grey</span>
这也是有道理的,因为 X11 color names (which CSS Colors Level 3 adapted from) 将 grey
拼写列为有效替代。
但是,为什么 CSS 颜色级别 3 不允许 colour
作为 属性?
.color {
color: red;
}
.colour {
colour: red;
}
<span class="color">color</span>
<span class="colour">colour</span>
规范的创建者允许替代值而非属性是否有特定原因?
有趣的是,这个选择的历史有据可查。
CSS 规范中有 this issue which talks about this point. In there Tab Atkins(tabatkins) links to this video 的 JSConf,由 Alex Sexton 提供,内容涉及 CSS 命名颜色背后的(非常有趣和有趣的)历史。
According to Sexton, the grey
value was initially added to MIT's rgb.txt 指定“X11 颜色”的文件,因为
some programmers at HP couldn't remember which one was right.
几年后,Chris Lilley(svgeesus) 将这些值添加到 SVG 颜色中,最终 CSS3(早在 2001 年)将如 Ian Hickson(Hixie) 所说,
[...] merely to codify current practice. Almost every browser supports them and that isn't going to change (because it would break many sites [...]
现在,这并没有告诉我们为什么我们没有 colour
属性。为此,让我们回到 CSS 问题,其中 tabatkins gives a hint that this is a recurrent request. The same svgeesus that did add the named colors to SVG back then also intervenes in this thread 并解释
The aliasing of international-English grey and US-English gray is least problematic as a property value (but would probably still not be adopted, were those keywords to be proposed today). As a functional notation, it would be more problematic; it would require precedence and de-duplicating rules in case both were specified. Even more so for aliasing the color
property to colour
(and the same for all the *-color*
properties.
Sorry, this would add far more issues than it solves.
作为主要使用英式英语的人,CSS 不接受 colour
作为有效 属性 的事实相当令人讨厌,尤其是 当它接受 grey
(及其偏差)作为有效值时。为什么 CSS 允许在值中使用英式英语,而不是在属性中?
根据 W3 CSS color specification,官方 CSS color
值的拼写是 gray
:
然而,它也接受grey
(及其偏差)就好了:
.gray {
color: gray;
}
.grey {
color: grey;
}
<span class="gray">gray</span>
<span class="grey">grey</span>
这也是有道理的,因为 X11 color names (which CSS Colors Level 3 adapted from) 将 grey
拼写列为有效替代。
但是,为什么 CSS 颜色级别 3 不允许 colour
作为 属性?
.color {
color: red;
}
.colour {
colour: red;
}
<span class="color">color</span>
<span class="colour">colour</span>
规范的创建者允许替代值而非属性是否有特定原因?
有趣的是,这个选择的历史有据可查。
CSS 规范中有 this issue which talks about this point. In there Tab Atkins(tabatkins) links to this video 的 JSConf,由 Alex Sexton 提供,内容涉及 CSS 命名颜色背后的(非常有趣和有趣的)历史。
According to Sexton, the grey
value was initially added to MIT's rgb.txt 指定“X11 颜色”的文件,因为
some programmers at HP couldn't remember which one was right.
几年后,Chris Lilley(svgeesus) 将这些值添加到 SVG 颜色中,最终 CSS3(早在 2001 年)将如 Ian Hickson(Hixie) 所说,
[...] merely to codify current practice. Almost every browser supports them and that isn't going to change (because it would break many sites [...]
现在,这并没有告诉我们为什么我们没有 colour
属性。为此,让我们回到 CSS 问题,其中 tabatkins gives a hint that this is a recurrent request. The same svgeesus that did add the named colors to SVG back then also intervenes in this thread 并解释
The aliasing of international-English grey and US-English gray is least problematic as a property value (but would probably still not be adopted, were those keywords to be proposed today). As a functional notation, it would be more problematic; it would require precedence and de-duplicating rules in case both were specified. Even more so for aliasing the
color
property tocolour
(and the same for all the*-color*
properties.Sorry, this would add far more issues than it solves.