Html <nav> 或 <menu> (HTML5)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4969801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
<nav> or <menu> (HTML5)
提问by zzzzBov
W3Schools.com and I'm pretty sure I remember seeing W3C.org state that <menu>
should be used for Toolbar menus and listing form control commands.
W3Schools.com,我很确定我记得看到 W3C.org 状态<menu>
应该用于工具栏菜单和列表表单控制命令。
So, which one should I use for my main menu? Nav
, or Menu
? Does it matter?
那么,我的主菜单应该使用哪一个?Nav
,或Menu
?有关系吗?
回答by zzzzBov
nav
is used for groups of internal links (a
elements). Generally this means the links should travel to separate pages, or change content in the case of an AJAX page. Expect some sort of content change when clicking on a nav
item.
nav
用于内部链接(a
元素)组。通常这意味着链接应该转到单独的页面,或者在 AJAX 页面的情况下更改内容。单击nav
项目时,预计会发生某种内容更改。
menu
is used for groups of controls (a
, input
, button
). Generally this means the inputs should perform a function within the page. Expect some sort of javascript interaction when clicking on a menu
item.
menu
用于控件组 ( a
, input
, button
)。通常这意味着输入应该在页面内执行一个功能。当点击一个menu
项目时,期待某种 javascript 交互。
nav
: the navigationfor the site.
nav
:网站导航。
menu
: the menufor a web application.
menu
:Web 应用程序的菜单。
回答by Su'
Here's an HTML5Doctor post on nav
with a section on how it's different from menu
(basically, use it in actual apps). Looks like you want nav
.
这是一篇HTML5Doctor 帖子,nav
其中有一节介绍了它与menu
(基本上,在实际应用程序中使用它)有何不同。看起来你想要nav
。
回答by Hyman
With the <menu>
it's usually used for context menus.
随着<menu>
它通常用于上下文菜单。
MDN has good documentation on it: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/menu
MDN 上有很好的文档:https: //developer.mozilla.org/en-US/docs/Web/HTML/Element/menu
回答by kevin
The best place to get this answer is the HTML 5 standards them self.
Menuis defined in HTML 5.1 2nd Edition.
获得此答案的最佳位置是他们自己的 HTML 5 标准。
菜单在HTML 5.1 第二版中定义。
It, "... represents a group of commands."
它,“……代表一组命令。”
Navis defined in HTML 5.
导航在HTML 5 中定义。
It is, "... a section of a page that links to other pages or to parts within the page: a section with navigation links."
它是,“...链接到其他页面或页面内部分的页面部分:带有导航链接的部分。”
There are notes for nav that I didn't include but think are important, but I think its best for you to get the definition yourself from the standards.
有一些我没有包含但认为很重要的导航注释,但我认为最好让您自己从标准中获得定义。
The definitions marked in this post as the answer are close to correct but have extraneous statements in them that make the answer itself wrong.
在这篇文章中标记为答案的定义接近正确,但其中有无关紧要的陈述,使答案本身是错误的。
回答by Nick Manning
<nav>
is a section (like <section>
or <article>
) so it will appear in your HTML document outline. Due to this, I would use <menu>
99% of the time. To me, <nav>
is a mix between <section>
and <menu>
, with the added constriction that <nav>
should be used specifically for navigation, whereas <menu>
can be for anything that might be called a menu (including a navigation bar). So most navigation bars, despite the fact that they are navigation bars, do not fit the strict requirements of <nav>
, and <menu>
is more appropriate.
<nav>
是一个部分(如<section>
或<article>
),因此它将出现在您的 HTML 文档大纲中。因此,我会使用<menu>
99% 的时间。对我来说,<nav>
是的混合体<section>
,并<menu>
与补充收缩是<nav>
应该专门用于导航使用,而<menu>
可为任何可能被称为菜单(包括导航栏)。所以大部分导航栏,虽然是导航栏,但并不符合 的严格要求<nav>
,<menu>
更合适。
I have never in my web development career found a situation where I wanted my navigation bar to be part of the document outline.
在我的 Web 开发生涯中,我从未发现过我希望我的导航栏成为文档大纲一部分的情况。