此信息不正确 -div
元素被视为flow content https://html.spec.whatwg.org/multipage/dom.html#flow-content-2并且很容易进入li https://html.spec.whatwg.org/multipage/grouping-content.html#the-li-element元素。你可能把它与ul
/ol
元素,其中可能只包含li
相应地。
HTML5 的变化是,它不再具有块级元素和内联元素。相反,有一个更复杂的区别元素分为几类 http://www.w3.org/TR/html5/dom.html#content-models.
要查看 HTML5 元素内允许的内容,请参阅该部分所在特定标记的描述“内容模型” https://html.spec.whatwg.org/multipage/dom.html#concept-element-content-model告诉您此特定元素中允许哪些内容。
编辑:解决有关列表元素的注释中的混乱
(根据截至2019-07-30的HTML生活标准)
There are several types of lists - the most common ones are unordered (ul) https://html.spec.whatwg.org/multipage/grouping-content.html#the-ul-element, and ordered (ol) https://html.spec.whatwg.org/multipage/grouping-content.html#the-ol-element lists. ul
and ol
are the "container" elements that only hold list item (li) https://html.spec.whatwg.org/multipage/grouping-content.html#the-li-element as child elements - no other elements are allowed*. The li
element itself can contain arbitrary flow content https://html.spec.whatwg.org/multipage/dom.html#flow-content-2.
* (technically they are also allowed to hold "script-supporting" elements https://html.spec.whatwg.org/multipage/dom.html#script-supporting-elements-2)
<ol>
<li></li>
...more li elements
</ol>
<ul>
<li></li>
...more li elements
</ul>
For 描述列表(dl) https://html.spec.whatwg.org/multipage/grouping-content.html#the-dl-element曾经有同样的限制,它们只能包含各自的子元素dt
and dd
,但最近的变化允许div
还有子元素,只要那些div
s 本身包含一个dt
or dd
.
<dl>
<dt>term</dt><dd>description</dd>
</dl>
// the following is now valid as well:
<dl>
<div><dt>term</dt><dd>description</dd></div>
</dl>
作为助记符:容器元素应该只包含它们各自的子元素,并且这些子元素可以包含您喜欢的任何内容。