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
Can <span> tags have any type of tags inside them?
提问by Alex
Are tags such as <div>
, <form>
, <pre>
etc.. allowed inside a <span>
?
被标记,如<div>
,<form>
,<pre>
等等。允许内<span>
?
回答by Wayne
The span
element 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.
Read about phrasing content here. This second link contains a full list of all the elements that can be put inside a SPAN element.