为什么跨度内的div是非法的?

时间:2021-01-20 05:26:47

It is not legal to have <div> elements within a <span> element. But if I understand it correctly, a <span> can be made to work like a <div> and vice versa by setting the CSS 'display' property to 'block' or 'inline'.

元素中包含

元素是不合法的。但是如果我理解正确的话,通过将CSS'display'属性设置为'block'或'inline',可以使
一样工作,反之亦然。

If it is that easy to bypass the containment rules, what is the point of having them?

如果容易绕过收容规则,那么拥有它们有什么意义呢?

2 个解决方案

#1


4  

It's illegal to have a div in a span because div is a bloc element, span is an inline element.
It's not related to rendering (CSS display) but on semantic.
Ask yourself, does it make sense to have a h1 inside a span ?

在span中包含div是非法的,因为div是一个bloc元素,span是一个内联元素。它与渲染(CSS显示)无关,而与语义无关。问问自己,在跨度内有一个h1是否有意义?

#2


1  

The issue is one of semantics. A Span element is expected to include Phrasing Content - i.e. the text of the document.

问题是语义之一。期望Span元素包括Phrasing Content - 即文档的文本。

A Div element is not phrasing content. It is for logical divisions of content.

Div元素不是措辞内容。它适用于内容的逻辑划分。

#1


4  

It's illegal to have a div in a span because div is a bloc element, span is an inline element.
It's not related to rendering (CSS display) but on semantic.
Ask yourself, does it make sense to have a h1 inside a span ?

在span中包含div是非法的,因为div是一个bloc元素,span是一个内联元素。它与渲染(CSS显示)无关,而与语义无关。问问自己,在跨度内有一个h1是否有意义?

#2


1  

The issue is one of semantics. A Span element is expected to include Phrasing Content - i.e. the text of the document.

问题是语义之一。期望Span元素包括Phrasing Content - 即文档的文本。

A Div element is not phrasing content. It is for logical divisions of content.

Div元素不是措辞内容。它适用于内容的逻辑划分。