如何在 HTML 中编写符合 W3C 标准的多级项目符号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4465562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to write W3C compliant multi-level bullet points in HTML?
提问by Techboy
Is it possible to write W3C compliant multi-level bullet points (unordered list) in HTML?
是否可以在 HTML 中编写符合 W3C 标准的多级项目符号(无序列表)?
Nested ul can be used, but is not W3C compliant.
可以使用嵌套的 ul,但不符合 W3C。
<ul>
<li>myItem 1</li>
<li>myItem 2</li>
<ul>
<li>myItem 2a</li>
</ul>
<li>myItem 3</li>
<li>myItem 4</li>
</ul>
- myItem 1
- myItem 2
- myItem 2a
- myItem 3
- myItem 4
- 我的项目 1
- 我的项目 2
- 我的项目 2a
- 我的项目 3
- 我的项目 4
In Visual Studio, the above code gives the warning: Validation (XHTML 1.0 Transitional): Element 'ul' cannot be nested within element 'ul'
在 Visual Studio 中,上面的代码给出警告:验证(XHTML 1.0 Transitional):元素“ul”不能嵌套在元素“ul”中
回答by David says reinstate Monica
The only valid child of either a ul
or ol
is an li
element; an li
can, however, contain a ul
(or ol
). To achieve your aim:
a ul
or的唯一有效子元素ol
是li
元素;li
但是,一个可以包含一个ul
(或ol
)。为了实现您的目标:
<ul>
? ? ?<li>myItem 1</li>
? ? ?<li>myItem 2</li>
<li style="list-style-type:none">
? ? ?<ul>
? ? ? ? <li>myItem 2a</li>
? ? ? </ul>
</li>
? ? ?<li>myItem 3</li>
? ? ?<li>myItem 4</li>
</ul>
回答by Marlon
Complementing David Thomas answer, this would remove the unwanted bullet:
补充大卫托马斯的回答,这将删除不需要的子弹:
<ul>
<li>myItem 1</li>
<li>myItem 2
<ul>
<li>myItem 2a</li>
</ul>
</li>
<li>myItem 3</li>
<li>myItem 4</li>
</ul>