CSS 选择器中的特殊字符

Special characters in CSS selector

我在 semantic UI 中找到了这个 CSS 定义。他们广泛使用这种风格。

.ui..buttons > .button,
.ui.two.buttons > .button {
  width: 50%;
}

我可以看到他们想要完成的事情。 他们希望 CSS 定义为

.ui.2.buttons > .button,

必须是ASCII码。代码 \32 将是 space。代码 \3 将是 "start of text".

你能解释一下这里发生了什么吗?为什么没有将 ascii 转换为 space? 为什么 W3C CSS validator 接受这个 CSS 而没有错误?

</code>是<em>十六进制</em>32,转化为十进制数50,确实就是字符<code>2</code> 将是 <code>1.

我从 W3C 规范中找到了这句话:

In CSS2, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [A-Za-z0-9] and ISO 10646 characters 161 and higher, plus the hyphen (-); they cannot start with a hyphen or a digit. They can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier “B&W?” may be written as “B\&W\?” or “B WF”.

我在 this arcticle which puts it in context, but it boils down to the fact that although normally class names cannot start with a number, it is allowed when the number is entered as an escaped character or (in this case) an ISO 10646 numeric code 中找到了一个字符的引用。