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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/css/214503.html

猜你在找的CSS相关文章