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

社会主义新天地 提交于 2019-12-17 07:23:18

问题


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


回答1:


The span element is an inline element, which should contain only other inline elements and no block elements.

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.

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.




回答2:


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

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.



来源:https://stackoverflow.com/questions/5545884/can-span-tags-have-any-type-of-tags-inside-them

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!