多个 < 导航 > 标记

我们可以在 html5的同一页面上使用多个标签吗?

我在 Zeldman 网站上读过 这个的文章,但是我并不完全清楚

也就是说。

<header><nav>links here</nav></header>


<footer><nav>links here</nav></footer>
54818 次浏览

Yes, absolutely. You can have multiple header, nav, and footer tags sans penalty.

As long as you're making sure you are using tags semantically and you aren't putting them in invalid places (they're block-level elements, so you can't put them inside an inline element, for example) then you shouldn't worry too much about what the sticklers are saying. It's all to easy to get caught up arguing about tiny details instead of moving forward on your project.

The answer is yes. You can have a <nav> tag in the footer, for more info check mdn <nav> documentation.

Yes, having multiple <nav> elements is absolutely ok.

You just have to make sure you're making them distinguishable for people using screen readers. You can do it by labelling each <nav> using aria-label.

<nav aria-label=’primary’>
<ul>
...List on links here...
</ul>
</nav>
<nav aria-label=’secondary’>
<ul>
...List on links here...
</ul>
</nav>

Or, if one of the <nav> as visible text on screen that can be identified as labelling element, you can use aria-labelledby like follows:

<nav aria-label="Site Menu">
<ul>
...List on links here...
</ul>
</nav>
<article>
<h1>Title</h1>
...
<nav aria-labelledby="id-1">
<h2 id="id-1">
Related Content
</h2>
<ul>
...List on links here...
</ul>
</nav>
</article>

You can read more about using Multiple Navigation Landmarks.