导航
前后页导航
在文章末尾显示前一页和后一页。
本页内容
前后页导航位于文章底部,由两个并排的链接组成。每个链接都是平坦的表面,目标页标题上方有一行低调的标签。链接用 rel="prev" 和 rel="next" 标明方向,样式表据此应用样式,无需为方向单独添加类名。
前后页导航
<nav class="pager max-w(560) mx-auto" aria-label="Guide pages"> <a class="pager-link" rel="prev" href="#installation"> <span class="pager-label"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(180 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(180 8 8)" /> </svg>Previous </span> <span class="pager-title">Installation</span> </a> <a class="pager-link" rel="next" href="#theming"> <span class="pager-label"> Next<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" /> </svg> </span> <span class="pager-title">Theming</span> </a></nav>import ArrowLeftIcon from '@master/icons-react/native/16/soft/arrow-left'import ArrowRightIcon from '@master/icons-react/native/16/soft/arrow-right'<nav className="pager max-w(560) mx-auto" aria-label="Guide pages"> <a className="pager-link" rel="prev" href="#installation"> <span className="pager-label"><ArrowLeftIcon className="icon" />Previous</span> <span className="pager-title">Installation</span> </a> <a className="pager-link" rel="next" href="#theming"> <span className="pager-label">Next<ArrowRightIcon className="icon" /></span> <span className="pager-title">Theming</span> </a></nav><script> import ArrowLeftIcon from '@master/icons-svelte/native/16/soft/arrow-left' import ArrowRightIcon from '@master/icons-svelte/native/16/soft/arrow-right'</script><nav class="pager max-w(560) mx-auto" aria-label="Guide pages"> <a class="pager-link" rel="prev" href="#installation"> <span class="pager-label"><ArrowLeftIcon class="icon" />Previous</span> <span class="pager-title">Installation</span> </a> <a class="pager-link" rel="next" href="#theming"> <span class="pager-label">Next<ArrowRightIcon class="icon" /></span> <span class="pager-title">Theming</span> </a></nav><script setup>import ArrowLeftIcon from '@master/icons-vue/native/16/soft/arrow-left'import ArrowRightIcon from '@master/icons-vue/native/16/soft/arrow-right'</script><template> <nav class="pager max-w(560) mx-auto" aria-label="Guide pages"> <a class="pager-link" rel="prev" href="#installation"> <span class="pager-label"><ArrowLeftIcon class="icon" />Previous</span> <span class="pager-title">Installation</span> </a> <a class="pager-link" rel="next" href="#theming"> <span class="pager-label">Next<ArrowRightIcon class="icon" /></span> <span class="pager-title">Theming</span> </a> </nav></template>#一个属性决定链接位置
rel 是 HTML 属性,用于说明链接与当前页面的关系,prev 和 next 是它的两个取值。前后页导航中的每个链接都使用其中一个值,正确表达页面的先后关系。样式表读取该属性,实现以下三点。
- 下一页链接位于行末,文字也向行末对齐。
- 指针悬停时,箭头沿所指方向移动:下一页向前,上一页向后。在从右向左的页面中,两个箭头都反向。
- 只有下一页链接时,它仍位于行末,方便读者看到并用拇指点按。
箭头是标签里的图标,使用 16px 的 Master Icons 图稿,由标签以 14px 显示:上一页在文字前放 arrow-left,下一页在文字后放 arrow-right。
省略没有对应页面的链接。指南的第一页只显示下一页,最后一页只显示上一页。
第一页
<nav class="pager max-w(560) mx-auto" aria-label="Guide pages"> <a class="pager-link" rel="next" href="#installation"> <span class="pager-label"> Next<svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" /> </svg> </span> <span class="pager-title">Installation</span> </a></nav>import ArrowRightIcon from '@master/icons-react/native/16/soft/arrow-right'<nav className="pager max-w(560) mx-auto" aria-label="Guide pages"> <a className="pager-link" rel="next" href="#installation"> <span className="pager-label">Next<ArrowRightIcon className="icon" /></span> <span className="pager-title">Installation</span> </a></nav><script> import ArrowRightIcon from '@master/icons-svelte/native/16/soft/arrow-right'</script><nav class="pager max-w(560) mx-auto" aria-label="Guide pages"> <a class="pager-link" rel="next" href="#installation"> <span class="pager-label">Next<ArrowRightIcon class="icon" /></span> <span class="pager-title">Installation</span> </a></nav><script setup>import ArrowRightIcon from '@master/icons-vue/native/16/soft/arrow-right'</script><template> <nav class="pager max-w(560) mx-auto" aria-label="Guide pages"> <a class="pager-link" rel="next" href="#installation"> <span class="pager-label">Next<ArrowRightIcon class="icon" /></span> <span class="pager-title">Installation</span> </a> </nav></template>#材质与动效
链接采用一道轮廓围合的平坦表面,圆角与大号控件一致。指针悬停时,链接抬高一层,箭头沿指向移动 2px。按下时,链接沉入凹槽。启用减少动态效果时,箭头保持原位。
前后页导航是一个尺寸容器。当自身宽度小于 26rem 时,两个链接上下排列,各自占满导航宽度,上一页排在最前。
#前后页导航与分页
前后页导航用于在按顺序阅读的页面之间切换,并显示目标页的标题。分页 用于在长列表的各个编号页之间切换。面包屑导航 显示当前页面在网站中的位置。
#无障碍
- 将链接放入带有
aria-label的<nav>中,让这个导航地标能与页面上的其他导航区分开。 - 链接的无障碍名称由标签和标题共同组成,例如“下一页,主题设置”。保留标签,用它说明链接指向上一页还是下一页。
- 箭头是带有
aria-hidden="true"的图标,读屏软件不会读出它们。
#类名
| 类名 | 说明 |
|---|---|
pager | 两个链接在带无障碍名称的 nav 内并排显示,容器宽度小于 26rem 时改为纵向排列。 |
pager-link | 一个带 rel="prev" 或 rel="next" 的链接:表面平坦,指针悬停时抬高一级。下一页链接位于末端,文字也向末端对齐 |
pager-label | 标题上方弱化显示的“上一页”或“下一页”标签,并带有指示翻页方向的图标:上一页的箭头在文字之前,下一页的箭头在文字之后。标签将图标设为 14px,并在从右向左的页面中将它反向 |
pager-title | 链接目标页面的标题 |