应该有多个
中的元素将其放在
    中标签?

发布于 2024-10-03 00:42:17 字数 2086 浏览 4 评论 0原文

我正在使用新的 HTML5 标签,我想知道以下两个选项中哪一个更可取:

选项 1

<article class="menu">
  <section>
    <header>
      <h4>Breakfast</h4>
    </header>
    <ul>
      <li>
        <article class="menu-item">Cereal</article>
      </li>
      <li>
        <article class="menu-item">Bacon & Eggs</article>
      </li>
      <li>
        <article class="menu-item">Waffles</article>
      </li>
    </ul>
  </section>
  <section>
    <header>
      <h4>Lunch</h4>
    </header>
    <ul>
      <li>
        <article class="menu-item">Peanut Butter & Jelly</article>
      </li>
      <li>
        <article class="menu-item">Ham Sammich</article>
      </li>
      <li>
        <article class="menu-item">Soup</article>
      </li>
    </ul>
  </section>
</article>

选项 2

<article class="menu">
  <section>
    <header>
      <h4>Breakfast</h4>
    </header>
    <article class="menu-item">Cereal</article>
    <article class="menu-item">Bacon & Eggs</article>
    <article class="menu-item">Waffles</article>
  </section>
  <section>
    <header>
      <h4>Lunch</h4>
    </header>
    <article class="menu-item">Peanut Butter & Jelly</article>
    <article class="menu-item">Ham Sammich</article>
    <article class="menu-item">Soup</article>
  </section>
</article>

由于 HTML 4.01 遗留下来的习惯,我目前正在使用第一个选项与标签,但在我看来它们在 HTML5 中是完全多余和不必要的。哪个更正确?

例如,在本文中,他们不使用标签: http://net.tutsplus.com/tutorials/html-css-techniques/html-5-and-css-3-the-techniques-youll-soon-be-using/

I'm using the new HTML5 tags and and I was wondering which of the following two options is preferable:

OPTION 1

<article class="menu">
  <section>
    <header>
      <h4>Breakfast</h4>
    </header>
    <ul>
      <li>
        <article class="menu-item">Cereal</article>
      </li>
      <li>
        <article class="menu-item">Bacon & Eggs</article>
      </li>
      <li>
        <article class="menu-item">Waffles</article>
      </li>
    </ul>
  </section>
  <section>
    <header>
      <h4>Lunch</h4>
    </header>
    <ul>
      <li>
        <article class="menu-item">Peanut Butter & Jelly</article>
      </li>
      <li>
        <article class="menu-item">Ham Sammich</article>
      </li>
      <li>
        <article class="menu-item">Soup</article>
      </li>
    </ul>
  </section>
</article>

OPTION 2

<article class="menu">
  <section>
    <header>
      <h4>Breakfast</h4>
    </header>
    <article class="menu-item">Cereal</article>
    <article class="menu-item">Bacon & Eggs</article>
    <article class="menu-item">Waffles</article>
  </section>
  <section>
    <header>
      <h4>Lunch</h4>
    </header>
    <article class="menu-item">Peanut Butter & Jelly</article>
    <article class="menu-item">Ham Sammich</article>
    <article class="menu-item">Soup</article>
  </section>
</article>

I'm currently using the first option with the tags due to habits leftover from HTML 4.01, however it seems to me that they are completely redundant and unnecessary in HTML5. Which is more correct?

For example, in this article here they don't use tags:
http://net.tutsplus.com/tutorials/html-css-techniques/html-5-and-css-3-the-techniques-youll-soon-be-using/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

冷清清 2024-10-10 00:42:17

应该?未必。能?是的。

我遇到的情况是,我正在使用

做与您的第一个示例类似的事情。在这种情况下,包含元素是

当然,图表不是文章。但这是规范所允许的,同时包含

。和<文章>。

  • 允许的内容是“流动内容”,其中包括,
  • 部分导航文章旁白标题 >页脚数字

    等。整个清单很长。因此,这取决于您在具体情况下感觉合适的方式。

    • 这些文章摘要是否用作按日期排序的文章全文的导航?如果我想要
    • ,我可能会做类似于上面对图所做的事情。想要一个额外的容器或者因为我喜欢这样。
    • 它是文章的全文,而不是您认为的文章列表吗?省略该列表。

    Should? Not necessarily. Can? Yes.

    I have a situation in which I am doing something similar to your first example with <figure>. In this case the containing element is <nav>. The figures are a list of items with a photo and title. It is a list of navigation items which are also figures. Thus nav > ... > li > figure.

    A figure isn't an article, of course. But it is permitted by the spec with both <figure> and <article>. Permitted contents of <li> are "flow content", which includes,

    section or nav or article or aside or header or footer or figure

    Among others. The whole list is long. So it depends on what feels right to you in your specific situation.

    • Are these article summaries that are serving as navigation to the full text of articles ordered by date? I might do something similar to what I did above with figure if I wanted the <li> for an additional container or because I liked it that way.
    • Is it the full text of articles, and not something you'd think of as a list of articles? Omit the list.
    不爱素颜 2024-10-10 00:42:17

    HTML 无论什么版本都只是数据集合的语义标记。如果使用列表来拆分文章在语义上有意义,那么这就是正确的方法。如果没有,那么它是不正确的。如果您只是担心通过网络发送的简约字节,那么您可以在任何版本的 html 中不使用该列表,并将其替换为段落标签。

    通常,语义标记与呈现数据的方式有更多关系,而不仅仅是数据。例如,如果您想使用类似 EasySlider,那么您必须将项目放入列表中,因为这是它使用的约定。以不同方式呈现的相同数据可能需要完全不同的标记。

    HTML no matter what version is just a semantic markup for a collection of data. If using a list to split apart the articles makes sense semantically, then that is the correct way. If it does not, then it is incorrect. If you are just worried about minimalistic bytes to send across the wire, then you could do without the list in any version of html and replace it with paragraph tags.

    Typically semantic markup has a little more to do with how you are presenting the data, than just the data alone. For instance, if you want to use something like EasySlider, then you have to put the items in a list because that is the convention it uses. The same data presented in a different way could require an entirely different markup.

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