试一试
<nav class="crumbs">
<ol>
<li class="crumb"><a href="#">Bikes</a></li>
<li class="crumb"><a href="#">BMX</a></li>
<li class="crumb">Jump Bike 3000</li>
</ol>
</nav>
<h1>Jump Bike 3000</h1>
<p>
This BMX bike is a solid step into the pro world. It looks as legit as it
rides and is built to polish your skills.
</p>
nav {
border-bottom: 1px solid black;
}
.crumbs ol {
list-style-type: none;
padding-left: 0;
}
.crumb {
display: inline-block;
}
.crumb a::after {
display: inline-block;
color: black;
content: ">";
font-size: 80%;
font-weight: bold;
padding: 0 3px;
}
属性
此元素仅包含全局属性。
用法说明
- 并非所有链接都必须包含在
<nav>
元素中。<nav>
仅用于主要的导航链接块;通常,<footer>
元素中包含的链接列表不需要放在<nav>
元素中。 - 一个文档可以有多个
<nav>
元素,例如,一个用于站点导航,另一个用于页面内导航。在这种情况下,可以使用aria-labelledby
来提高可访问性,请参阅 示例。 - 用户代理,例如针对残障用户的屏幕阅读器,可以使用此元素来确定是否应忽略导航内容的初始渲染。
示例
在此示例中,<nav>
块用于包含一个无序列表(<ul>
)的链接。通过适当的 CSS,这可以呈现为侧边栏、导航栏或下拉菜单。
html
<nav class="menu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
nav
元素的语义是提供链接。然而,nav
元素不一定必须包含列表,它也可以包含其他类型的内容。在这个导航块中,链接是通过散文提供的。
html
<nav>
<h2>Navigation</h2>
<p>
You are on my home page. To the north lies <a href="/blog">my blog</a>, from
whence the sounds of battle can be heard. To the east you can see a large
mountain, upon which many <a href="/school">school papers</a> are littered.
Far up this mountain you can spy a little figure who appears to be me,
desperately scribbling a <a href="/school/thesis">thesis</a>.
</p>
<p>
To the west are several exits. One fun-looking exit is labeled
<a href="https://games.example.com/">"games"</a>. Another more
boring-looking exit is labeled <a href="https://isp.example.net/">ISP™</a>.
</p>
<p>
To the south lies a dark and dank <a href="/about">contacts page</a>.
Cobwebs cover its disused entrance, and at one point you see a rat run
quickly out of the page.
</p>
</nav>
技术摘要
内容类别 | 流内容、区块内容、可感知内容。 |
---|---|
允许内容 | 流内容. |
标签省略 | 无,起始标签和结束标签都必须存在。 |
允许父级 | 任何接受流内容的元素。 |
隐式 ARIA 角色 |
navigation
|
允许的 ARIA 角色 | 不允许 role |
DOM 接口 | HTMLElement |
规范
规范 |
---|
HTML # the-nav-element |
浏览器兼容性
加载中…