HTML5 sub nav semantics

亡梦爱人 提交于 2020-01-01 04:47:11

问题


A quick question re: HTML5 nav, specifically that of sub navigation (from a semantic point of view).

I have <nav> in the header for the main menu. Down the left of a standard page I have second level nav and down the right third level nav (no, I didn’t design the site). Is there anything I can do HTML5/ARIA wise to differentiate between the 3 menus? Or are they all simple <nav> blocks?

I dont even think I need <aside> in either left or right column as there isnt any additional info apart from these actual menus.

Any thoughts/advice would be much appreciated.


回答1:


This may be an old question, but there is a better answer now:

You can label each navigation section implicitly using headings, and explicitly use WAI-ARIA attributes:

<nav role="navigation" aria-labelledby="firstLabel">
  <h2 span id="firstLabel" class="hidden">Main menu</h2>
  <ul/>
</nav>
...
<nav role="navigation" aria-labelledby="secondLabel">
  <h2 span id="secondLabel" class="hidden">Local pages</h2>
  <ul/>
</nav>

For user-agents like screenreaders, they can report that as "Local pages, navigation" (although they vary in how it's reported).

Read more on a W3C wiki page on using labelledby.




回答2:


I would differentiate between the navigation sections by giving them semantically relevant ids and by placing them in order of importance in the HTML code, along the following lines:

<body>
  <nav id="main-navigation">
    <!-- The main menu goes here -->
  </nav>
  <nav id="sub-navigation">
    <!-- The left hand menu goes here -->
  </nav>
  <nav id="leaf-navigation">
    <!-- The right hand third level menu goes here -->
  </nav>

  <section id="content">
    <!-- Actual page content -->
  </section>
</body>

Other than that, I see no real need for further differentiation between the sections. The above approach is easy to understand, should be reasonably easy to style and is semantically clear, which is certainly good enough for me.



来源:https://stackoverflow.com/questions/6061867/html5-sub-nav-semantics

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!