作为主要使用英式英语的人,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 (其中 CSS 颜色级别 3 adapted from)将 grey
拼写列为有效替代。
但是,为什么 CSS Colors Level 3 不允许将 colour
作为属性?
.color {
color: red;
}
.colour {
colour: red;
}
<span class="color">color</span>
<span class="colour">colour</span>
规范的创建者允许替代值而非属性是否有特定原因?
最佳答案
非常有趣的是,这个选择的历史有据可查。
CSS 规范有 this issue其中谈到了这一点。在那里 Tab Atkins(tabatkins) 链接到 this video Alex Sexton 给出的关于 CSS 命名颜色背后的(非常有趣和有趣)历史的 JSConf。
According to Sexton , grey
值最初被添加到麻省理工学院的 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
属性。为此,让我们回到 tabatkins gives a hint 的 CSS 问题。这是一个经常性的请求。同样的 svgeesus 当时确实将命名颜色添加到 SVG 中也是 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.
关于css - 为什么 CSS 接受 'grey' 而不是 'colour' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70430577/