这两者之间符合哪个标准?
<p>Text text text ...
<ol>
<li>First element</li>
</ol>
</p>
<p>
Other text text ...
</p>
或
<p>
Text text text ...
</p>
<ol>
<li>First element</li>
</ol>
<p>
Other text text ...
</p>
最佳答案
简短的回答是 ol
元素在法律上是不允许在 p
元素中使用的。
要了解原因,让我们 go to the spec !如果您对 HTML 规范感到满意,它将回答您的许多问题和好奇心。您想知道 ol
是否可以存在于 p
中。所以……
Categories: Flow content, Palpable content.
Content model: Phrasing content.
Categories: Flow content.
Content model: Zero or more li and script-supporting elements.
第一部分说p
元素只能包含phrasing content (它们是“内联”元素,例如 span
和 strong
)。
第二部分说ol
是flow content (“ block ”元素,如 p
和 div
)。所以它们不能在 p
中使用。
ol
s 和其他 flow content
可以用在其他一些元素中,例如 div
:
Categories: Flow content, Palpable content.
Content model: Flow content.
关于html - ol/ul 应该在 <p> 内部还是外部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5681481/