微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CSS 3还允许省略最终分号吗?

在CSS语法模块3级规范即将到来的草稿中似乎有一个突破(即向后不兼容)的变化:现在可能需要在块中最后一个声明之后的后缀分号.

比较旧的措辞(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级建议中当然是作为有效的例子)将不再验证?

有可能有更多关于整个3级草稿收藏的知识吗?对于面向未来的样式表,我们真的需要检查现有的CSS文件(如果缺少,请插入分号),然后才能最终确定规范,或者我误解了某些内容

解决方法

看起来当前的规格有歧义.

你正确地指出,2. Syntax Description section规定用分号结束每个规则:

Each declaration has a property name,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的兼容性,并将在最终版本中重写其语法描述部分.

原文地址:https://www.jb51.cc/css/214503.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。