段落元素中的无序列表 [英] unordered list in a paragraph element

查看:131
本文介绍了段落元素中的无序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我写这篇文章时:

 < p class =paragraph>列表:
< ; UL>
< li>项目< / li>
< / ul>
< / p>

我的浏览器在语义上呈现为:

 < p class =paragraph>清单:< / p> 
< ul>
< li>项目< / li>
< / ul>
< p>< / p>

为什么?有没有更好的方法在段落中引入列表项?根据 HTML 5.0 规范,一个段落可能包含 //www.w3.org/TR/html5/dom.html#phrasing-content-1rel =noreferrer>短语内容,其中仍然不包含其他分组元素:



http://www.w3.org/TR/html5/grouping-content.html#the-p-element



根据 HTML 4.01 规范中,一个段落可能只包含内联元素:

http://www.w3.org/TR/html401/struct/text.html#h-9.3.1

  9.3.1段落:P元素

<!ELEMENT P - O(%inline ;)* - 段落 - >
<!ATTLIST P
%attrs; - %coreattrs,%i18n,%events -
>

在这种情况下,正确的标记是在开始列表之前关闭段落。

或者,您可以使用除段落以外的其他标签(如< div> ),这样。

 < div> 
< ul> ...< / ul>
< / div>


when I write this:

<p class="paragraph">the list:
  <ul>
    <li>item</li>
  </ul>
</p>

my browser is semantically rendered it as:

<p class="paragraph">the list:</p>
<ul>
  <li>item</li>
</ul>
<p></p>

why ? and is there a better way to introduce list-items in a paragraph ?

解决方案

According to the HTML 5.0 specification, a paragraph may contain phrasing content, which still does not include other grouping elements:

http://www.w3.org/TR/html5/grouping-content.html#the-p-element

According to the HTML 4.01 specification, a paragraph may only contain inline elements:

http://www.w3.org/TR/html401/struct/text.html#h-9.3.1

9.3.1 Paragraphs: the P element

<!ELEMENT P - O (%inline;)*            -- paragraph -->
<!ATTLIST P
  %attrs;                              -- %coreattrs, %i18n, %events --
  >

The correct markup in this case is to close your paragraph before starting the list.

Alternatively, you can use another tag other than paragraph (like <div>) which is not processed in this way.

<div>
   <ul> ... </ul>
</div>

这篇关于段落元素中的无序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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