LI 元件内空 UL
谁能解释一下为什么
elementa 不能为空?为什么这个 HTML:
<ul>
<li class="header">
<a href="#">Work</a>
<ul/>
</li>
<li class="header">
<a href="#">New</a>
<ul/>
</li>
<li class="header">
<a href="#">Ungrouped</a>
<ul/>
</li>
<li class="header">
<a href="#">Offline</a>
<ul/>
</li>
</ul>
会这样呈现:
- 工作
- 新
- 未分组
- 离线
Can anyone explain me why <ul>
elementa cannot be empty?
And why this HTML:
<ul>
<li class="header">
<a href="#">Work</a>
<ul/>
</li>
<li class="header">
<a href="#">New</a>
<ul/>
</li>
<li class="header">
<a href="#">Ungrouped</a>
<ul/>
</li>
<li class="header">
<a href="#">Offline</a>
<ul/>
</li>
</ul>
is rendered like this:
- Work
- New
- Ungrouped
- Offline
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不是有效的自关闭标签,因此浏览器可能会将其视为未正确关闭。您应该始终使用结束
标记。
有关有效自关闭标签的列表,请参阅:
XHTML 中所有有效的自关闭元素(由主要浏览器实现)有哪些?
<ul>
is not a valid self-closing tag, so browsers may treat it as though it has not been closed properly. You should always use a closing</ul>
tag.For a list of valid self-closing tags, see:
What are all the valid self-closing elements in XHTML (as implemented by the major browsers)?
一只手拍手的声音是什么?
从文档的角度来看,其中包含零个项目的列表没有任何意义,而 HTML 是一种文档标记语言。
因此,该规范定义了一个列表,要求至少其中的一个列表项。
至于你的第二个问题,在 HTML Compatible XHTML 仅定义为EMPTY(即 HTML 中禁止使用结束标记的标记)可以(并且必须)使用自结束标记语法。
What is the sound of one hand clapping?
A list with zero items in it doesn't make sense from a document point of view, and HTML is a document markup language.
The specification therefore defines a list as requiring at least one list item in it.
As for your second question, in HTML Compatible XHTML only elements which are defined as being EMPTY (i.e. those in which the end tag is forbidden in HTML) may (and must) use self-closing tag syntax.
因为浏览器(通常)不支持自关闭 XML 样式标签。这将起作用:
有关更多详细信息,请参阅: 可以使用
关闭跨度吗
?Because browsers (usually) don't support self closing XML-style tags. This will work:
For more details see: Can a span be closed using
<span />
?