Html 导航角色=导航

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14911038/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:40:03  来源:igfitidea点击:

nav role=navigation

htmlsemantic-markup

提问by Artem Svirskyi

I'm a little confused with roles. If I have in my page a navigation that is enclosed in a navelement and specify a role="navigation".

我对角色有点困惑。如果我的页面中有一个包含在nav元素中的导航并指定一个role="navigation".

<nav role="navigation">
    ...
</nav>

Isn't it already semantically explicit that the navsection is navigation?

nav部分是导航在语义上不是已经很明确了吗?

Or if I have some other navigation sections on my page, and specify role for only one of them, this section becomes the most important on a page? And those without role="navigation"just boring navigations?

或者,如果我的页面上还有一些其他导航部分,并且只为其中一个指定角色,那么该部分将成为页面上最重要的部分?那些没有role="navigation"无聊的导航?

采纳答案by Mike

It is true that most modern browsers/technologies recognise the HTML5 <nav>element as navigation and give it the same attention. But explicitly setting the role="navigation"attribute just makes sure that a lot more technologies can pick it up.

确实,大多数现代浏览器/技术都将 HTML5<nav>元素识别为导航并给予同样的关注。但是显式设置role="navigation"属性只是为了确保更多的技术可以使用它。

For example screen-readers and other technologies for users with disabilities are very rarely fully standards compliant (especially if they have to work all the way back to IE6 or lower!) so adding the role attributes explicitly always ensures that you cover all your bases for the most users possible.

例如,针对残障用户的屏幕阅读器和其他技术很少完全符合标准(特别是如果他们必须一直工作到 IE6 或更低版本!)因此明确添加角色属性始终确保您涵盖所有基础尽可能多的用户。

Also (and this is just a guess) some of the lesser known search engines may not fully recognise HTML5 yet, so adding these roles should help with the sites crawl-ability.

此外(这只是一个猜测)一些鲜为人知的搜索引擎可能还不能完全识别 HTML5,因此添加这些角色应该有助于网站的抓取能力。

回答by Albert Vila Calvo

Take a look at thisfrom W3C. It says:

看看这个来自 W3C。它说:

In the majorityof cases setting an ARIA role and/or aria-* attribute that matches the default implicit ARIA semantics is unnecessary and not recommendedas these properties are already set by the browser.

大多数情况下,设置匹配默认隐式 ARIA 语义的 ARIA 角色和/或 aria-* 属性是不必要的,也不推荐,因为浏览器已经设置了这些属性。

So doing <main role="main">is unnecessary and not recommended. That said, the Bootstrap's navbar examples(which everybody -including me- copy-pastes) come with <nav role="navigation">.

所以这样做<main role="main">不必要的,也不推荐。也就是说,Bootstrap 的导航栏示例(每个人 - 包括我 - 复制粘贴)都带有<nav role="navigation">.

To be honest, I'm not sure what's correct.

老实说,我不确定什么是正确的。

回答by Hans Grimm

W3C recommends: "However, in order to make the structure more accessible to user agents that support ARIA as well as ensuring that user agents that don't support HTML5 can also understand the structure, adding the ARIA role="navigation" is advised." https://www.w3.org/WAI/GL/wiki/Using_HTML5_nav_element

W3C 建议:“但是,为了使支持 ARIA 的用户代理更容易访问该结构,并确保不支持 HTML5 的用户代理也可以理解该结构,建议添加 ARIA role="navigation"。 ” https://www.w3.org/WAI/GL/wiki/Using_HTML5_nav_element