- 中标签?
应该有多个中的元素将其放在
我正在使用新的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该?未必。能?是的。
我遇到的情况是,我正在使用
当然,图表不是文章。但这是规范所允许的,同时包含
等。整个清单很长。因此,这取决于您在具体情况下感觉合适的方式。
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,
Among others. The whole list is long. So it depends on what feels right to you in your specific situation.
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.