使用section元素作为页面主要内容部分在语义上正确吗?
发布于 2013-02-14 19:55:38
大体上说,没有。
HTML5Doctor says:
我们一直在做的错误是使用来包装内容以定义样式,或者使用来区分主要内容区域div、页眉、页脚等。
自从那篇文章写完之后,<main>元素就应运而生了,专门用于您的用例。
发布于 2013-02-14 19:52:18
您可以,但我建议您改用新的main元素!
例如:
<main role="main">
</main>参见the main element和further examples on using the main element。
发布于 2013-02-15 20:25:16
您可以说,一旦有一个标题(h1-h6)不是分段元素的标题,您就隐含地使用了section。
因此,这两个文档在语义上是等价的:
1)
<body>
<h1>John's cool site</h1>
<nav>…</nav>
<h2>A nice article</h2> <!--- main content starts with this heading -->
<p>I like bees.</p>
</body> <!-- main content ends at the end of the document -->2)
<body>
<h1>John's cool site</h1>
<nav>…</nav>
<section><!--- main content starts with this opening tag -->
<h2>A nice article</h2> <!-- now you could use h1 here, too -->
<p>I like bees.</p>
</section><!-- main content ends with this closing tag -->
</body>所以,是的,您可以对主要内容使用section (尽管在许多情况下,article会更合适)。您可以对每个标题内容组使用section (当然,除非应该使用article、nav或aside )。
一旦对所有这些标题-内容组使用了sectioning元素,就可以在任何地方使用h1。
甚至在一些边缘情况下,您将被要求显式地使用主要内容的部分元素。也就是说,如果您的页面包含的内容不是主要内容的一部分,并且不适合header、footer或address (也不适合aside/nav)。如果在这种情况下不使用section (或article),则此内容仍将属于主内容。
一个更常见的(我甚至要说,非常)你应该使用section/article作为主要内容的例子是,你需要一个单独的header/footer作为主要内容的页面,例如博客帖子页面:整个页面可能有一个footer (它包含关于整个博客的信息)。现在,如果我们不对主要内容使用区段元素(→博客帖子),我们就不可能有一个单独的footer (包含作者信息、标签、类别等)。只是为了那篇文章。
<body>
<h1>John's blog</h1>
<article>
<h1>My first blog post</h1>
<p>…</p>
<footer> <!-- applies to the blog post only (article) -->
Tags: introduction, aboutme
</footer>
</article>
<footer> <!-- applies to the whole page (body) -->
Blog of John Doe — 2013
<p><small>All content licensed under Creative Commons</small></p>
</footer>
</body>因此,我建议:如果有疑问,可以显式地使用section/article作为页面的主要内容。
https://stackoverflow.com/questions/14874156
复制相似问题