Html 什么叫不需要结束标签的标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3741896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What do you call tags that need no ending tag?
提问by Emanuil Rusev
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?
有一些 HTML 标记,例如<img />
,<input />
和<button />
,不需要结束标记(</img>
,</input>
和</button>
)。描述此类标签的术语是什么?
回答by Mark Byers
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
HTML 4.x
I can't find any mention of this syntax in the HTML 4.x specification. It is not valid syntax.
我在 HTML 4.x 规范中找不到任何提及此语法的内容。它不是有效的语法。
HTML 5
HTML 5
In the HTML 5 specification the /
character (called a SOLIDUS) is valid but has no effect for void elementssuch 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).
在HTML 5规范的/
字符(称为SOLIDUS)是有效的,但是有没有效果无效元素,例如<br />
,<hr />
,<img />
,<input />
,等,并为外来元素(如SVG标签),它指定标记为自开始标记关闭。它不是所有其他标签的有效语法(例如<button />
您的问题中提到的)。
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.
然后,如果元素是空元素之一,或者元素是外来元素,则可能只有一个 U+002F SOLIDUS 字符 (/)。这个字符对 void 元素没有影响,但对外部元素它把开始标签标记为 self-closed。
XML
XML
According to the XML specificationit is called an empty-element tag:
根据XML 规范,它被称为空元素标签:
The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag.
空元素的表示要么是紧跟在结束标签之后的开始标签,要么是空元素标签。
XHTML
XHTML
According to the XHTML specificationit is called the minimized tag syntax for empty elements:
根据XHTML 规范,它被称为空元素的最小化标记语法:
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 syntaxfor 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 Minimizationand 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 />).
C.2. 空元素
在空元素的尾随 / 和 > 之前包含一个空格,例如 <br />、<hr /> 和 <img src="karen.jpg" alt="Karen" />。此外,对空元素使用最小化的标记语法,例如 <br />,因为 XML 允许的替代语法 <br></br> 在许多现有用户代理中给出了不确定的结果。
C.3. 元素最小化和空元素内容
给定内容模型不是 EMPTY 的元素的空实例(例如,空标题或段落)不要使用最小化形式(例如,使用 <p> </p> 而不是 <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.
一般来说,如果您想准确一些,我建议您使用相应标准中定义的名称。然后,如果人们不确定您的意思,他们可以在标准中查找以找出答案。但是,如果您不想在标准中使用该名称,您可以随意将其命名为其他名称。重要的是与你交流的人能够理解你。如果您在 XML 文档中对标签使用术语“自闭合标签”,我认为没有人会误解您,即使标准正式将其称为其他名称。
Thanks to Alohci for the HTML 5 reference.
感谢 Alohci 提供 HTML 5 参考。
回答by tvanfosson
The term is self-closing.
该术语是自动关闭的。
回答by Alpesh
HTML tags can be of two types. They are
HTML 标签可以有两种类型。他们是
Paired Tags
Unpaired Tags
配对标签
未配对标签
Paired Tags:
配对标签:
A tag is said to be a paired tag if the text is placed between a tag and its companion tag. In paired tags, the first tag is referred to as Opening Tag and the second tag is referred to as Closing Tag.
如果文本位于标签与其伴随标签之间,则称该标签为配对标签。在配对标签中,第一个标签称为开始标签,第二个标签称为结束标签。
Example:
<i>
This text is in italics. </i>
示例:
<i>
此文本为斜体。</i>
Note: Here <i>
is called opening tag. and </i>
is called closing tag.
注:这里<i>
称为开标。并</i>
称为结束标记。
Unpaired Tags:
未配对标签:
An unpaired tag does not have a companion tag. Unpaired tags are also known as Singular or Stand-Alone Tags.
未配对的标签没有伴随标签。未配对的标签也称为单一标签或独立标签。
Example : <br> , <hr>
etc. These tags does not require any companion tag.
示例:<br> , <hr>
等。这些标签不需要任何伴随标签。
回答by Joey Ezekiel
I've always called them Singleton tags!
我一直称它们为单例标签!
回答by foo
This sort of Element is an empty element (since it does not contain anything, it just may have attributes). That's the correct way according to the specification, AFAIK. (If the Element is not empty, the Element consists of the opening tag, the closing tag, and the content inbetween.)
这种元素是一个空元素(因为它不包含任何东西,它可能只有属性)。根据规范,AFAIK,这是正确的方法。(如果 Element 不为空,则 Element 由开始标签、结束标签和中间的内容组成。)
Those tags are also called "unpaired", "single", or "bachelor tags". The term "self-closing" I don't like because they don't close themselves any more than other tags, it's still you or your program that puts the "/>" in there.
这些标签也称为“未配对”、“单一”或“单身汉标签”。我不喜欢“自关闭”这个词,因为它们不会像其他标签一样关闭自己,仍然是您或您的程序将“/>”放在那里。
回答by Prakash Thangavelu
Those tags are called "Standalone Tags". Standalone tags are having no closing tags in HTML
这些标签被称为“独立标签”。独立标签在 HTML 中没有结束标签
But in XHTML they have to be self closed by adding forward slash before the closing angular bracket
但在 XHTML 中,它们必须通过在结束角括号前添加正斜杠来自我关闭
回答by Dennis Haarbrink
That is called a self closing tag
这就是所谓的自闭标签
回答by Trevor
I know them as bachelor tags.
e.g. here: http://moodle.cs.huji.ac.il/cs09/file.php/67782/xml-intro.pdf(page 30)
我知道它们是单身汉标签。
例如这里:http: //moodle.cs.huji.ac.il/cs09/file.php/67782/xml-intro.pdf(第30页)
回答by AcidSoldier
I've called them self-closing, single tags and monotags, I don't know why I haven't adopted a single term though.
我称它们为自闭合、单标签和单标签,但我不知道为什么我没有采用一个术语。
回答by troelskn
I've seen them referred to as singlet (Which is presumably a short form of single-tag)
我见过它们被称为单线态(这大概是单标签的一种简短形式)