gpt4 book ai didi

css - CSS 3 还会允许省略最后的分号吗?

转载 作者:技术小花猫 更新时间:2023-10-29 10:36:52 26 4
gpt4 key购买 nike

即将发布的 CSS Syntax Module Level 3 规范草案似乎有一个突破性的(即向后不兼容的)变化:现在可能需要在 block 中的最后一个声明之后添加尾随分号。

比较旧的措辞(W3C Working Draft 13 August 2003):

4.8. Rule sets, declaration blocks, and selectors A declaration-block (also called a {}-block in the following text) starts with a left curly brace ({) and ends with the matching right curly brace (}). In between there must be a list of zero or more semicolon-separated (;) declarations.

使用新的(Editor's Draft 14 June 2012):

2. Description of CSS's Syntax A rule starts with a selector (defined by the Selectors specification), then has a {}-wrapped block containing a sequence of declarations. The selector specifies which elements the declarations will apply to. Each declaration has a property name, followed by a colon and the property value, and finished with a semicolon.

(强调我的)。

所以漂亮的简短形式,例如:

em { color: lime }

(目前在 CSS 颜色模块级别 3 推荐中作为有效示例给出)将不再有效。

能否请更了解整个 Level 3 草稿集的人验证一下?对于面向 future 的样式表,我们是否真的必须在规范最终确定之前彻底检查现有的 CSS 文件(如果缺少则插入分号),还是我误解了什么?

最佳答案

看起来目前规范中存在歧义。

您正确地指出了 2. Syntax Description section规定每条规则以分号结束:

Each declaration has a property name, followed by a colon and the property value, and finished with a semicolon.

同时,3.6.8. Declaration-value mode 节中对解析自动机的描述读到没有分号的右大括号正确地同时结束了声明和当前规则:

} token

Append the current declaration to the value of the current rule. Pop the current rule from the stack of open rules, and append it to the value of the new current rule. Switch to the current rule's content mode.

所以根据 3.6.8 尾随分号是可选的。

我不能说规范作者的实际意图。但目前的情况可能应该报告和修复。可以肯定的是,他们无意破坏与 CSS 2.1 的兼容性,并将在最终版本中重写他们的语法说明部分。

关于css - CSS 3 还会允许省略最后的分号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11062615/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com