且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

你打什么标签,不需要结束标签?

更新时间:2022-10-14 19:02:09

这种语法有多种名称,具体取决于您使用的语言。找出所谓的***的方法是查看特定语言的规范。

HTML 4.x



在HTML 4.x规范中我找不到任何这种语法。这是无效的语法。



HTML 5 在HTML 5规范中 / 字符(称为SOLIDUS)是有效的,但对< br /> ,< hr />#void-elementsrel =noreferrer> void elements ; ,< img /> <输入/> 等以及它指定的外国元素(例如SVG标签) 标记为自动关闭的开始标记。它不是所有其他标记的有效语法(例如在您的问题中提到的< button /> )。然后,如果元素是void元素之一,或者如果元素是外部元素,那么可能会有一个单一的U + 002F SOLIDUS字符(/)。此字符对void元素没有影响,但在外部元素上标记开始标记为自动关闭



根据 #dt-eetagrel =noreferrer> XML规范它被称为空元素标记


空元素的表示形式可以是紧跟在尾标签后面的开始标记,也可以是空元素标记



XHTML



根据 XHTML规范它被称为空元素的最小化标签语法


C.2。空元素

在空元素的尾部和/或>之前包含空格,例如, < hr />和< img src =karen.jpgalt =凯伦/>。此外,对空元素使用最小化标记语法,例如作为XML允许的替代语法< / br>在许多现有的用户代理中给出了不确定的结果。



C.3。元素最小化和空元素内容

给定内容模型不是EMPTY的元素的空实例(例如,空标题或段落)不要使用最小化的表单(例如,使用< p>< / p>而不是< p />).


一般来说,如果你想精确,我会建议使用相应标准中定义的名称。然后,如果人们不完全确定你的意思,他们可以在标准中查找它以找出答案。但是,如果您不想在标准中使用该名称,则可以***地将其称为其他名称。重要的是与你交流的人可以理解你。我不认为有人会误解你,如果你在XML文档中为标签使用'self-closing tag'这个词,即使这个标准正式把它称为别的东西。



感谢Alohci为HTML 5引用。


There are HTML tags, such as <img />, <input /> and <button />, that need no ending tag (</img>, </input> and </button>). What is the term that describes this type of tags?

This syntax has a variety of names depending on what language you are using. The best way to find out what it is called is to look at the specification for the specific language.

HTML 4.x

I can't find any mention of this syntax in the HTML 4.x specification. It is not valid syntax.

HTML 5

In the HTML 5 specification the / character (called a SOLIDUS) is valid but has no effect for void elements such as <br />, <hr />, <img />, <input />, etc. and for foreign elements (such as SVG tags) it designates a start tag that is marked as self-closing. It is not a valid syntax for all other tags (such as <button /> mentioned in your question).

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

XML

According to the XML specification it is called an empty-element tag:

The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag.

XHTML

According to the XHTML specification it is called the minimized tag syntax for empty elements:

C.2. Empty Elements

Include a space before the trailing / and > of empty elements, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />. Also, use the minimized tag syntax for empty elements, e.g. <br />, as the alternative syntax <br></br> allowed by XML gives uncertain results in many existing user agents.

C.3. Element Minimization and Empty Element Content

Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph) do not use the minimized form (e.g. use <p> </p> and not <p />).

In general if you want to be precise I would recommend using the names as defined in the appropriate standard. Then if people aren't exactly sure what you mean they can look it up in the standard to find out. However if you don't want to use the name in the standard you are free to call it something else if you want. The important thing is that the people who communicate with you can understand you. I don't think anyone would misunderstand you if you used the term 'self-closing tag' for a tag in an XML document even if the standard officially calls it something else.

Thanks to Alohci for the HTML 5 reference.