如果ol / ul在里面< p>或外面? [英] Should ol/ul be inside <p> or outside?

查看:86
本文介绍了如果ol / ul在里面< p>或外面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 < p>文字文字... 
< p< ;醇>
< li>第一个元素< / li>
< / ol>
< / p>
< p>
其他文字文字...
< / p>



OR



 < p为H. 
文字文字...
< / p>
< ol>
< li>第一个元素< / li>
< / ol>
< p>
其他文字文字...
< / p>


解决方案

简短的答案是 ol 元素在 p 元素内不合法。



要明白为什么, 转到规范!如果您可以习惯HTML规范,它将回答您的许多问题和好奇心。你想知道 ol 是否可以存在于 p 内。所以...


4.5.1 p 元素


分类: 流量内容可触摸内容

内容模式: 短语内容








4.5.5 ol 元素


分类: 流内容

内容模式l :零或多个 li 脚本支持元素。



第一部分说 p 元素可以仅包含措辞内容(这是内联元素如 span strong )。 第二部分说 ol s 流内容(块元素,如 p div )。所以他们不能用在 p 内。




ol s和其他流量内容可用于其他元素,如 div


4.5.13 div元素


类别: 流程内容可触摸内容。 >
内容模式: 流量内容




Which is standard compliant between these two ?

<p>Text text text ... 
    <ol>
        <li>First element</li>
    </ol>
</p>
<p>
    Other text text ...
</p>

OR

<p>
    Text text text ... 
</p>
<ol>
    <li>First element</li>
</ol>
<p>
    Other text text ...
</p>

解决方案

The short answer is that ol elements are not legally allowed inside p elements.

To see why, let's go to the spec! If you can get comfortable with the HTML spec, it will answer many of your questions and curiosities. You want to know if an ol can live inside a p. So…

4.5.1 The p element:

Categories: Flow content, Palpable content.
Content model: Phrasing content.


4.5.5 The ol element:

Categories: Flow content.
Content model: Zero or more li and script-supporting elements.

The first part says that p elements can only contain phrasing content (which are "inline" elements like span and strong).

The second part says ols are flow content ("block" elements like p and div). So they can't be used inside a p.


ols and other flow content can be used in in some other elements like div:

4.5.13 The div element:

Categories: Flow content, Palpable content.
Content model: Flow content.

这篇关于如果ol / ul在里面&lt; p&gt;或外面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆