我可以使用< nav>分页标签? [英] Can I use the <nav> tag for pagination?
问题描述
在主菜单导航中看到标记< nav>
的使用情况很常见,但我不知道其他可以使用它的示例。例如,对于分页:
It's very common to see the usage of the tag <nav>
in a main menu navigation, but I don't know other examples where I can use it. For example, for pagination:
<div class='my-pagination'>
<!-- first, 2, 3, 4 ... 8, 9, last -->
</div>
可以是:
<nav class='my-pagination'>
<!-- first, 2, 3, 4 ... 8, 9, last -->
</nav>
是语义吗?
推荐答案
是。
HTML5规范定义了 nav
元素,如下所示:
The HTML5 spec defines the nav
element like this:
nav
元素表示链接到其他页面的页面的一部分或到页面中的部分:带有导航链接的部分。
The
nav
element represents a section of a page that links to other pages or to parts within the page: a section with navigation links.
分页显然包含其他页面的链接,这些是导航链接。在大多数情况下,为此使用分段内容元素是有意义的。
Pagination clearly consists of "links to other pages", and these are "navigation links". And in probably most cases it makes sense to use a sectioning content element for this.
确保放置 nav
在正确的父节中:
Make sure to place the nav
in the correct parent section:
-
如果这是一篇多页的文章,
nav
应该是文章
的孩子。
<article>
<h1>Review of my new camera</h1>
<p>…</p>
<nav><!-- pagination for this article --></nav>
</article>
如果是多页的文章摘要列表, nav
应该是包含此列表的部分的子项。
If it’s a multi-paged list of article teasers, the nav
should be a child of the section containing this list.
<section>
<h1>All blog posts</h1>
<article><h1>Review of my new camera</h1></article>
<article><h1>I want to buy a camera, any suggestions?</h1></article>
<nav><!-- pagination for this blog posts list --></nav>
</section>
如果是每页一篇完整的文章, nav
应该是正文
切根的子节点。
If it’s one full article per page, the nav
should be a child of the body
sectioning root.
<body>
<article><h1>Review of my new camera</h1></article>
<nav><!-- pagination for next/previous article --></nav>
</body>
这篇关于我可以使用< nav>分页标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!