简体   繁体   English

为什么 CSS 接受“灰色”而不接受“颜色”?

[英]Why does CSS accept 'grey' but not 'colour'?

As someone who primarily uses British English, the fact that CSS does not accept colour as a valid property is rather irksome, especially when it accepts grey (and its deviations) as valid values.作为主要使用英式英语的人,CSS 不接受colour作为有效属性这一事实相当令人讨厌,尤其是当它接受grey (及其偏差)作为有效值时。 Why would CSS allow for British English in values, not but in properties?为什么 CSS 允许英式英语的值,而不是属性?

According to the W3 CSS color specification , the official spelling for the CSS color value is gray :根据W3 CSS 颜色规范,CSS color值的官方拼写为gray

颜色规格

However, it also accepts grey (and its deviations) just fine:但是,它可以接受grey (及其偏差):

 .gray { color: gray; }.grey { color: grey; }
 <span class="gray">gray</span> <span class="grey">grey</span>

This also makes sense, given that the X11 color names (which CSS Colors Level 3 adapted from ) list the grey spellings as valid alternatives.这也是有道理的,因为X11 颜色名称(其中 CSS Colors Level 3改编自)将grey拼写列为有效替代品。

But why then, does CSS Colors Level 3 not allow for colour as a property?但是,为什么 CSS Colors 级别 3 不允许将colour作为属性?

 .color { color: red; }.colour { colour: red; }
 <span class="color">color</span> <span class="colour">colour</span>

Is there a specific reason that the creators of the specification would allow for alternatives to values but not properties?规范的创建者是否有特定的原因允许替代值而不是属性?

Quite interestingly, the history of this choice is quite well documented.非常有趣的是,这种选择的历史是有据可查的。

The CSS specs has this issue which talks about this point. CSS 规范有这个问题,它谈到了这一点。
In there Tab Atkins(tabatkins) links to this video of a JSConf given by Alex Sexton about the (quite fascinating and funny) history behind the CSS named colors.在那里,Tab Atkins(tabatkins) 链接到这个由 Alex Sexton 提供的 JSConf 视频,该视频讲述了名为 colors 的 CSS 背后的(非常有趣和有趣的)历史。

According to Sexton , the grey value was initially added to MIT's rgb.txt file that specifies "X11 colors", because根据 Sexton的说法, grey值最初被添加到 MIT 的指定“X11 颜色”的rgb.txt文件中,因为

some programmers at HP couldn't remember which one was right.惠普的一些程序员不记得哪一个是正确的。

A few years later, Chris Lilley(svgeesus) will add these values to the SVG colors, and finally CSS3 (as early as in 2001) will follow as Ian Hickson(Hixie) puts it,几年后,Chris Lilley(svgeesus) 会将这些值添加到 SVG colors 中,最后 Z2BE25667A86187FFE0B9A61DD3C85073DZ 将在 2

[...] merely to codify current practice. [...] 只是为了编纂当前的做法。 Almost every browser supports them and that isn't going to change (because it would break many sites [...]几乎每个浏览器都支持它们并且这不会改变(因为它会破坏许多站点 [...]

Now, that doesn't tell us why we don't have a colour attribute.现在,这并没有告诉我们为什么我们没有colour属性。
For this let's come back to the CSS issue where tabatkins gives a hint that this is a recurrent request.为此,让我们回到 CSS 问题, tabatkins 提示这是一个经常性请求。 The same svgeesus that did add the named colors to SVG back then also intervenes in this thread and explains that将命名的 colors 添加到 SVG 的同一svgeesus介入了这个线程并解释说

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.color属性别名为colour更是如此(对于所有*-color*属性也是如此。

Sorry, this would add far more issues than it solves.抱歉,这会增加比它解决的问题更多的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM