HTML5 - <li> 是否必须在 <ul> 内?

标签 html syntax

我知道,<ul> 的独子可以是<li>元素。但是,我找不到任何要求,无论是<li>可以在没有 <ul> 的情况下使用元素?

下面的代码是否正确?

<p>some elements, nevermind</p>
<li>Oh! This has a point</li>
<li>another one!</li>
<p>and here the rest of the site goes...</p>

我知道,这似乎毫无意义,但我写了一些非常基本的 CMS,其中我需要用列表元素替换 [[li]] 标记,所以如果上面是正确的,我不会需要做很多逻辑,在第一个 [[li]] 之前添加元素,在最后一个之后添加 。

总而言之 - HTML5 语法允许我使用

  • 而不使用
      吗?

  • 最佳答案

    直接来自 W3 HTML5 Spec (这是一个候选规范,我实际上建议 kazagistar's W3 link其中包括 <menu>元素也是。):

    4.5.7 The li element

    Categories: None. Contexts in which this element can be used: Inside ol elements. Inside ul elements.

    The li element represents a list item. If its parent element is an ol, or ul, then the element is an item of the parent element's list, as defined for those elements. Otherwise, the list item has no defined list-related relationship to any other li element.

    W3 规范表明,您应该只在有序或无序列表元素或菜单元素中使用列表项元素。

    关于HTML5 - <li> 是否必须在 <ul> 内?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21033532/

    相关文章:

    javascript - 如何知道输入了某些文本并且光标已离开文本框?

    javascript - 有什么方法可以使 javascript 中的嵌套回调代码更具可读性吗?

    python - Python 中更好的 "return if not None"

    Java 双下划线符号是做什么用的?

    syntax - Clojure:[_] 在函数参数列表中做了什么?

    html - float : left breaks container div?

    html - 如何在 css 中使用类中的特定单词?

    swift 3 更新 swift 2 的语法

    javascript - 如何在标签中显示富文本区域的内容

    php - HTML 链接无法打开到窗口中