Tag omission: The start tag is mandatory,but,as it is a void element,
the use of an end tag is forbidden.
之前我从来没听说过一个空白的元素. MDN没有页面的空白元素,但empty element page说:
Note: In very rare cases,empty elements are referred to as void
elements. This is an improper name and should be avoided.
但是,W3 spec仅仅指的是空白元素,从未提到空元素:
A void element is an element whose content model never allows it to
have contents under any circumstances. Void elements can have
attributes.
所以我想知道:
>如果这些是相同的东西,它们应该被称为空元素,而不是void元素?那么W3规范是否已经过时了,不被信任?或者W3规范是否优先,即使是过时的?
>如果它们不一样,< col span =“2”/>有效的语法或应该是< col span =“2”> (没有斜杠),因为结束标签是禁止的?我可能对“结束标签”有错误的想法,但我一直以为/> (< br />和< img />)作为结束标签.
解决方法
The allowed content for an element is called its content model. Element types that are designed to have no content are called empty elements. The content model for such element types is declared using the keyword “EMPTY”.
使用img元素的示例声明:
This example illustrates the declaration of an empty element type:
06000
- The element type being declared is IMG.
- The hyphen and the following “O” indicate that the end tag can be omitted,but together with the content model “EMPTY”,this is strengthened to the rule that the end tag must be omitted.
- The “EMPTY” keyword means that instances of this type must not have content.
XML定义了一个“空的元素”:
[Definition: An element with no content is said to be empty.]
这里的区别是,XML并不表示“空元素”是“内容模型为空的元素”.相反,它只是说“空元素”是没有内容的元素.这是不管文档类型或XML模式是否将特定元素定义为不需要内容? XML本身并不存在这样的限制.
另外一个术语“空元素标签”用于描述快捷语法/>通常用于指示空元素(再次,无论它们是否定义都为空).这通常也被称为“自我关闭”语法.
术语“void element”是HTML5的新功能.它具有与“空元素”的HTML5前定义相同的定义:即仅具有起始标记,无结束标记,并且不能包含任何内容的元素.虽然W3C HTML5规范没有引用术语“空元素”,但是在related document中使用了XML中描述的术语“空元素标签”:
In the HTML Syntax,void elements are elements that always are empty and never have an end tag. All elements listed as void 07004 or in an extension spec,MUST in polyglot markup have the syntactic form of an XML 07005 (
<foo/>
). Other elements MUST NOT use the XML empty-element tag Syntax.
现在的HTML标准似乎更喜欢XML定义并避开以前的定义.这似乎是合适的,因为现代HTML不再是SGML应用程序,而是自己的标记语言. (它也不是XML,但是这就是polyglot标记的发挥.)
所以,总结一下:
>一个空的元素是没有内容的元素,无论是否允许首先拥有内容.
>一个void元素是不能有任何内容的元素.
另外,可以说所有的void元素都是空的元素,但是一个空的元素并不一定代表一个void元素.
回答你的问题:
>
If these are the same thing,should they be referred to as empty elements and never as void elements? In that case,is the W3 spec outdated and not to be trusted? Or should the W3 spec take precedence,even if it is outdated?
像在HTML5中,像area,br,col和img这样的元素更准确地称为void元素.它们也被认为是空的,但只因为它们不能是“非空”.
我不知道为什么MDN有一篇文章说“[‘Void elements’]是一个不正确的名称,应该避免.当它在大多数HTML引用中使用该名称时.我没有理由不信任官方规格.
>
If they are not the same thing,is
<col span="2" />
valid Syntax or should it be<col span="2">
(without the slash) because the end tag is forbidden? I may have the wrong idea of “end tag” but I’ve always thought of the/>
(as in<br />
and<img />
) to be an end tag of sorts.
< col span =“2”/>只是有效的语法,因为HTML5认为它是一种流行的方式来标记无效元素感谢XHTML,并且不允许它不必要地破坏与许多XHTML文档的验证兼容性,否则它们将被验证为HTML5. HTML5本身定义了/>是无意义的(在one specific exception这里并不真正相关),所以实际上< col span =“2”/>在HTML5中,只是代表一个只有一个起始标记和没有结束标记的列,因此与< col span =“2”>相同,尽管是XML友好的.