a 标签为什么能够包含块级元素

2020-01-19  本文已影响0人  agamgn

前言

 a标签按照以往的标准,他属于内联元素,不应该包含块级元素,但是他又是可以包含的, 这是为什么呢?
 按新的 HTML 规范,已经不按 inline 和 block 来区分元素类型了。

原因

 在规范中每个元素会规定如下两项:

a 元素的 content model 为 transparent

Some elements are described as transparent; they have "transparent" in the description of their content model. The content model of a transparent element is derived from the content model of its parent element: the elements required in the part of the content model that is "transparent" are the same elements as required in the part of the content model of the parent of the transparent element in which the transparent element finds itself.

 大意就是这类元素本身内部可以有任何类型的内容,是否合法要看其父元素的 content model 和其内容的 categories。

 比如我们要看 p > ins > a > div 是否合法,过程是这样的:

总结

 对于各种新标准,还是需要了解的

上一篇 下一篇

猜你喜欢

热点阅读