Should I be using nav or ul

2020-02-26 07:05发布

I'm making a navigation menu, should I be using the <nav> element or <ul> element for that?

If I use a nav I'll prob need to use a shiv so that it works across browsers.

If that's so, what the advantage of using a nav over a ul?

EDIT:

I know you can put a ul into a nav my question is why use a nav at all?

8条回答
够拽才男人
2楼-- · 2020-02-26 07:44

Depends on the case but most of the time you'll be using both.

<nav>
    <ul>
        <li><a href="#">item1</a></li>
        <li><a href="#">item2</a></li>
        <li><a href="#">item3</a></li>
        <li><a href="#">item4</a></li>
        <li><a href="#">item5</a></li>
    </ul>
</nav>

<!-- Or just links -->

<nav>
    <a href="#">Item</a>
    <a href="#">Item</a>
    <a href="#">Item</a>
</nav>

Both are semantically correct.

查看更多
何必那么认真
3楼-- · 2020-02-26 07:46

The nav element is semantically more specific, so generally the better choice. A search engine, for example, will understand that the links within it represent navigation, rather than a simple list of links (which could be recommended posts, or related items etc).

查看更多
登录 后发表回答