简体   繁体   English

html5 NAV TAG正确使用

[英]html5 NAV TAG proper usage

I've begun to use html tags on my pages, and I'm trying to determine what is the proper usage of the NAV tag.我已经开始在我的页面上使用 html 标签,并且我正在尝试确定 NAV 标签的正确用法。 I've read the documentation, and it seems like I should be okay with what I have, but I noticed that most other developers have their navigation 'blocks' within "ul" "li" tags.我已经阅读了文档,似乎我应该可以接受我所拥有的,但我注意到大多数其他开发人员在“ul”“li”标签中都有他们的导航“块”。 I've using divs.我用过div。

My question is, what are the pros / cons to using "ul" "li" tags rather than divs?我的问题是,使用“ul”“li”标签而不是 div 的优点/缺点是什么?

And would the following work with nav?以下内容是否适用于导航?

<nav>
    <div id="navBar">
        <div id="navItem1"><a></a></div>
        <div id="navItem2"><a></a></div>
        <div id="navItem3"><a></a></div>
        <div id="navItem4"><a></a></div>
    </div>
</nav>

The code you posted isn't a best practice.您发布的代码不是最佳实践。 It should be:它应该是:


<nav>
    <ul>
        <li><a></a></li>
        <li><a></a></li>
        <li><a></a></li>
        <li><a></a></li>
    </ul>
</nav>

<ul> and <li> tags are better than using div tags, and are almost always used for menus. <ul><li>标签比使用div标签更好,并且几乎总是用于菜单。 By using ul s and li s, you don't clog up your code with WAY too many IDs.通过使用ul s 和li s,你不会用太多的 ID 阻塞你的代码。

Lists (ul, ol) can have additional meaning in accessible browsers (screen readers and the like) while divs do not.列表 (ul, ol) 在可访问的浏览器(屏幕阅读器等)中可以具有其他含义,而 div 则没有。 This makes it easier for these users to use your site and one of the reasons lists are preferred for menus.这使这些用户更容易使用您的网站,这也是菜单首选列表的原因之一。

Also, as others said, list tags give the content some context (menus are lists of links) while divs have no context.此外,正如其他人所说,列表标签为内容提供了一些上下文(菜单是链接列表),而 div 没有上下文。

by custom, a navigation bar is considered a list of links, hence the ul-li.按照惯例,导航栏被认为是链接列表,因此是 ul-li。 there is no actual difference, just a common practice没有实际的区别,只是一种常见的做法

what you are doing is fine, altought maybe i'd replace the div#navBar directly with a nav#navBar, to reduce an anidation level你在做什么很好,也许我会直接用 nav#navBar 替换 div#navBar,以降低动画级别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM