Nest lists in paragraphs in html

后端 未结 5 2089
长情又很酷
长情又很酷 2020-12-11 15:57

It seems that (strict) html doesn\'t allow nesting any non-inline elements inside a

, but then how am I supposed to render a paragraph that contains a

5条回答
  •  误落风尘
    2020-12-11 16:05

    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:

    • Consider reaching for a more broad-reaching flow element than paragraph if it applies, such as section, nav, header, footer, or article.
    • Use a hybrid approach: wrap the p – ol – p sequence with a div of your choosing that applies common formatting to the set.

    As far as 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.

提交回复
热议问题