制作 HTML 嵌套列表的正确方法? [英] Proper way to make HTML nested list?
问题描述
W3 文档有一个嵌套列表示例以 DEPRECATEDEXAMPLE: 为前缀,但他们从来没有用一个非弃用的例子纠正它,也没有解释这个例子到底有什么问题.
The W3 docs have a nested list example prefixed by DEPRECATED EXAMPLE:
, but they never corrected it with a non-deprecated example, nor explained exactly what is wrong with the example.
那么以下哪种方式是编写 HTML 列表的正确方式?
So which of these ways is the correct way to write an HTML list?
选项 1:嵌套的
是父
<ul>
<li>List item one</li>
<li>List item two with subitems:</li>
<ul>
<li>Subitem 1</li>
<li>Subitem 2</li>
</ul>
<li>Final list item</li>
</ul>
选项 2:嵌套的
是它所属的 的子元素
Option 2: the nested <ul>
is a child of the <li>
it belongs in
<ul>
<li>List item one</li>
<li>List item two with subitems:
<ul>
<li>Subitem 1</li>
<li>Subitem 2</li>
</ul>
</li>
<li>Final list item</li>
</ul>
推荐答案
选项 2 是正确的.
嵌套列表应该在嵌套列表的元素内.
The nested list should be inside a <li>
element of the list in which it is nested.
列表中的 W3C Wiki 链接(摘自以下评论):HTML 列表 Wiki.
Link to the W3C Wiki on Lists (taken from comment below): HTML Lists Wiki.
链接到 HTML5 W3C ul
规范:HTML5 ul
.请注意,ul
元素可能包含恰好零个或多个 li
元素.这同样适用于 HTML5 ol
.描述列表 (HTML5 dl
) 类似,但允许 dt
和 dd
元素.
Link to the HTML5 W3C ul
spec: HTML5 ul
. Note that a ul
element may contain exactly zero or more li
elements. The same applies to HTML5 ol
.
The description list (HTML5 dl
) is similar, but allows both dt
and dd
elements.
更多注意事项:
dl
= 定义列表.ol
= 有序列表(数字).ul
= 无序列表(项目符号).
dl
= definition list.ol
= ordered list (numbers).ul
= unordered list (bullets).
这篇关于制作 HTML 嵌套列表的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!