CSS 3仍然允许省略最后的分号? [英] Will CSS 3 still allow omitting final semicolons?

查看:261
本文介绍了CSS 3仍然允许省略最后的分号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



比较旧的字词( W3C工作草案2003年8月13日):


4.8。规则集,声明块和选择器

声明块(在下面的文本中也称为{}块)以左大括号({)开头,以大括号})。其间必须有一个或多个分号 - 分隔符(;)声明的列表。


2012年6月14日编辑草稿):


2。 CSS语法的描述

规则从一个选择器(由Selectors规范定义)开始,然后有一个{}封装的包含一系列声明的块。选择器指定声明将应用于哪些元素。每个声明都有一个属性名称,后面是冒号和属性值,并且完成后加上分号。


(强调我的)。



这样漂亮的短格式例如:

  em {color:lime} 

作为CSS颜色模块3级建议中的有效示例)将不再有效?



有人能更了解整个3级草稿集合,请验证吗?对于面向未来的样式表,我们真的必须在规范定稿之前彻底改进现有的CSS文件(如果缺少,请插入分号),否则我会误解某些东西吗?

解决



你正确地指出, 2。语法说明section 规定以分号结束每个规则:


每个声明都有一个属性名称,后跟一个冒号和属性值,并以分号结束。


同时,在 3.6.8。声明值模式读取没有分号的结束大括号同时正确结束了声明和当前规则:


}令牌



将当前声明附加到当前规则的值。从打开的规则的堆栈中弹出当前规则,并将其附加到新的当前规则的值。


因此,根据 3.6.8 ,尾随分号是可选的。

我不能说说规范作者的实际意图。但目前的情况应该报告和修正。当然,他们并不打算破坏与CSS 2.1的兼容性,并会在最终版本中重写他们的语法描述部分。


There seems to be a breaking (i.e. backwards-incompatible) change in the CSS Syntax Module Level 3 specification upcoming draft: trailing semicolon after the last declaration in a block is now perhaps required.

Compare the old wording (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.

with the new one (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.

(emphasis mine).

So that nifty short forms e.g.:

em { color: lime }

(this is currently given as valid example in the CSS Color Module Level 3 recommendation) will no longer validate?

Could someone more knowledgeable about the whole Level 3 drafts collection please verify? To future-proof stylesheets do we really have to overhaul existing CSS-files (and insert semicolons if missing) before the spec gets finalized or did I misunderstand something?

解决方案

Looks like there currently is an ambiguity in the spec.

You correctly pointed out that 2. Syntax Description section prescribes ending every rule with a semicolon:

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

And at the same time, description of the parsing automaton in section 3.6.8. Declaration-value mode reads that a closing brace without a semicolon correctly ends a declaration and current rule at the same time:

} 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.

So according to 3.6.8 trailing semicolon is optional.

I can't say about actual intention of the specification authors. But current situation should probably be reported and fixed. Most certainly they don't have intention of breaking the compatibility with CSS 2.1 and will reword their Syntax Description section in the final version.

这篇关于CSS 3仍然允许省略最后的分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆