Rumah >hujung hadapan web >Tutorial H5 >a 标签为什么能够包含块级元素?
按照html嵌套规则行内元素不能包含块级元素,a标签为什么可以包含
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。
When an inline box contains an in-flow block-level box, the inline box (and its inline ancestors within the same line box) are broken around the block-level box (and any block-level siblings that are consecutive or separated only by collapsible whitespace and/or out-of-flow elements), splitting the inline box into two boxes (even if either side is empty), one on each side of the block-level box(es). The line boxes before the break and after the break are enclosed in anonymous block boxes, and the block-level box becomes a sibling of those anonymous boxes. When such an inline box is affected by relative positioning, any resulting translation also affects the block-level box contained in the inline box.
This model would apply in the following example if the following rules:
<code class="language-text">p { display: inline } span { display: block } </code>我以前写样式经常这样写或者后来才知道这是错的,因为后台快疯了,看着a标签总是包含在最外面,虽然效果是可以显示出来的,但是后台已疯 p>div, 这个不行; a>div单看可以 最新的HTML标准是a标签不能包含div,在IE下没事,但是在其它浏览器中就截断了 HTML5标准定义可以这么做:
4.5 Text-level semantics
The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g. buttons or other links). ...used to make an entire advertising block into a link