LI 元件内空 UL

发布于 2024-09-02 19:05:59 字数 739 浏览 1 评论 0原文

谁能解释一下为什么

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可爱咩 2024-09-09 19:05:59

    不是有效的自关闭标签,因此浏览器可能会将其视为未正确关闭。您应该始终使用结束

标记。

有关有效自关闭标签的列表,请参阅:

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)?

甚是思念 2024-09-09 19:05:59

一只手拍手的声音是什么?

从文档的角度来看,其中包含零个项目的列表没有任何意义,而 HTML 是一种文档标记语言。

因此,该规范定义了一个列表,要求至少其中的一个列表项。

<!ELEMENT UL - - (LI)+                 -- unordered list -->

至于你的第二个问题,在 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.

<!ELEMENT UL - - (LI)+                 -- unordered list -->

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.

请叫√我孤独 2024-09-09 19:05:59

因为浏览器(通常)不支持自关闭 XML 样式标签。这将起作用:

<ul>
    <li class="header">
        <a href="#">Work</a>
        <ul></ul>
    </li>
    <li class="header">
        <a href="#">New</a>
        <ul></ul>
    </li>
    <li class="header">
        <a href="#">Ungrouped</a>
        <ul></ul>
    </li>
    <li class="header">
        <a href="#">Offline</a>
        <ul></ul>
    </li>
</ul>

有关更多详细信息,请参阅: 可以使用 关闭跨度吗

Because browsers (usually) don't support self closing XML-style tags. This will work:

<ul>
    <li class="header">
        <a href="#">Work</a>
        <ul></ul>
    </li>
    <li class="header">
        <a href="#">New</a>
        <ul></ul>
    </li>
    <li class="header">
        <a href="#">Ungrouped</a>
        <ul></ul>
    </li>
    <li class="header">
        <a href="#">Offline</a>
        <ul></ul>
    </li>
</ul>

For more details see: Can a span be closed using <span />?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文