巢在html中的段落中列出 [英] Nest lists in paragraphs in html
问题描述
< p>
中嵌套任何非内联元素,但是我该如何呈现段落包含一个列表(在自然文本中经常出现的东西)。我见过三个答案,看起来都不令人满意: - 列表不应该出现在段落内。 (我不打算进入文化辩论,但我当然希望html不会成为写作风格的地方。)
- 将文本分成段落,然后是一个列表,然后是带有后文的第二段。这看起来很糟糕,因为现在我有段落的 c>< p> 块,这对于标记尝试使用一些
< div class =mypara>
- 这看起来像一个假的段落坏的方法来绕过整个事情,并放弃使用标记正确的文本语义。
是否有其他方式做到这一点在语义上是正确的和有效的?
HTML 5中的段落是最新的工作草案,只能包含短语元素的元素。列表也被定义为流程元素,并且可能不包含在段落中。无论你认为段落的定义应该是什么,这是HTML中术语的正式定义,我认为它不太可能改变。
有两种可能性,你可能会考虑除了你提到的两个: 就 It seems that (strict) html doesn't allow nesting any non-inline elements inside a Is there some other way to do this that is semantically correct and valid? Paragraphs in HTML 5, as of the latest working draft, are defined as flow elements which can contain phrasing elements only. Lists are also defined as flow elements, and may not be enclosed in paragraphs. Whatever you think the definition of paragraph should be, this is the formal definition of the term in HTML, and I think it's unlikely to change. There are two possibilities that you might consider besides the two you've mentioned: As far as 这篇关于巢在html中的段落中列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
部分
, nav
,标头
, footer
或 article 。
div
,代价是 p
您。然而,它可以用于确保多段落的使用不会太过于视觉上的不连贯。<p>
, but then how am I supposed to render a paragraph that contains a list (something that occurs often in natural texts). I've seen three answers that all seem unsatisfying:
<p>
chunks that are parts of paragraphs, and that seems bad for a markup that is trying to to move in a more semantic direction.<div class="mypara">
— which looks like a bad way to bypass the whole thing and give up on using the markup with the proper semantics for text.
section
, nav
, header
, footer
, or article
.p – ol – p
sequence with a div
of your choosing that applies common formatting to the set.div
goes, the HTML 5 spec clearly recommends that it should be a "last resort" element because it doesn't bear semantic meaning in the way that other HTML elements do, and may not be as user-friendly in alternative user agents. Going by this advice, I wouldn't use div
at the cost of p
for body text if semantics are important to you. However, it can be useful in making sure that the use of multiple paragraphs does not get too visually choppy.