Html <span> 标签可以包含任何类型的标签吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5545884/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:47:39  来源:igfitidea点击:

Can <span> tags have any type of tags inside them?

htmlxhtml

提问by Alex

Are tags such as <div>, <form>, <pre>etc.. allowed inside a <span>?

被标记,如<div><form><pre>等等。允许内<span>

回答by Wayne

The spanelement is an inlineelement, which should contain only other inlineelements and no blockelements.

span元素是一个内联元素,它应该只包含其他内联元素,而不能包含元素。

From the spec:

规范

Generally, block-level elements may contain inline elements and other block-level elements. Generally, inline elements may contain only data and other inline elements. Inherent in this structural distinction is the idea that block elements create "larger" structures than inline elements.

通常,块级元素可能包含行内元素和其他块级元素。通常,内联元素可能只包含数据和其他内联元素。这种结构区别的固有思想是块元素创建比行内元素“更大”的结构。

The generic block-level grouping element is the div. The generic inline-level grouping element is the span.

通用的块级分组元素是div. 通用的内联级分组元素是span.

Again, from the spec:

再次,从规范

The DIV and SPAN elements, in conjunction with the id and class attributes, offer a generic mechanism for adding structure to documents. These elements define content to be inline (SPAN) or block-level (DIV) but impose no other presentational idioms on the content.

DIV 和 SPAN 元素与 id 和 class 属性一起提供了一种向文档添加结构的通用机制。这些元素将内容定义为内联 (SPAN) 或块级 (DIV),但不会对内容施加其他表现形式。

回答by ?ime Vidas

According to the HTML Living Standard, the content model for SPAN elements is "Phrasing content".

根据HTML Living Standard,SPAN 元素的内容模型是“短语内容”。

Read about the SPAN element here.

在此处阅读有关 SPAN 元素的信息

Read about phrasing content here. This second link contains a full list of all the elements that can be put inside a SPAN element.

在此处阅读有关措辞内容的信息。第二个链接包含可以放入 SPAN 元素的所有元素的完整列表。