網站導覽

v2.1.0
網站導覽

前後頁導覽

在文章底部提供上一篇和下一篇的連結。

本頁內容

前後頁導覽放在文章底部,以兩個並排的連結指向上一篇和下一篇。每個連結都是平坦的面板,在目的頁面的標題上方放一個低調的方向標籤。連結以 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連結所指向的頁面標題

#原始程式碼

@master/ui/components/pager.css
/* * Pager: the page before and the page after, at the foot of an article. * Two links side by side, each a flat face with a quiet word over the title of the page it leads to. The * links say which is which with rel="prev" and rel="next", and the stylesheet reads that: the next page * stands at the end with its words set to the end, and an arrow points the way each one goes. The arrow is an * icon in the markup, beside the word: the stylesheet sizes it, moves it and turns it in a right-to-left page. * A pager with only a next page keeps it at the end. * Under the pointer a link rises a step and its arrow moves 2px the way it points. In a narrow container the * two stack. * Geometry: a large control's corner, 14px by 16px of padding, 12px between the two. */@layer components.ui {  .pager {    container-type: inline-size;    display: grid;    grid-template-columns: repeat(2, minmax(0, 1fr));    gap: .75rem;    min-width: 0;    margin: 0;    padding: 0;    list-style: none;    @container (width < 26rem) {      .pager-link, .pager-link[rel~="next"] {        grid-column: 1 / -1;      }    }  }  .pager-link {    --pager-travel: 0px;    display: grid;    gap: .125rem;    min-width: 0;    padding: .875rem 1rem;    border-radius: calc(var(--radius-control-lg) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--color-surface-raised);    color: var(--color-text-body);    box-shadow: var(--shadow-flat);    text-decoration: none;    touch-action: manipulation;    -webkit-tap-highlight-color: transparent;    transition: box-shadow var(--duration-quick) var(--easing-glide);    /* The page after: at the end, with its words set to the end. */    &[rel~="next"] {      grid-column: 2;      justify-items: end;      text-align: end;    }    @media (hover: hover) {      &:hover {        --pager-travel: 2px;        box-shadow: var(--shadow-raised);      }    }    &:active {      background: var(--color-surface-inset);      box-shadow: var(--shadow-pressed);      transition-duration: var(--duration-press);    }    &:focus-visible {      @apply --focus-ring;    }    @media (prefers-reduced-motion: reduce) {      --pager-travel: 0px;      @media (hover: hover) {        &:hover {          --pager-travel: 0px;        }      }    }    @media (forced-colors: active) {      outline: 1px solid LinkText;      outline-offset: -1px;    }  }  /*   * The quiet word: Previous, Next. The icon beside it is its arrow, 14px, which the label holds before the word   * of the page before and after the word of the next.   */  .pager-label {    --icon-size: .875rem;    display: inline-flex;    align-items: center;    gap: .25rem;    margin: 0;    color: var(--color-text-muted);    font-size: .78125rem;    line-height: 1.25rem;    .icon {      transition: translate var(--duration-quick) var(--easing-glide);    }  }  /* Under the pointer an arrow moves the way it points: back for the page before, on for the next. */  .pager-link:not([rel~="next"]) .pager-label .icon {    translate: calc(-1 * var(--pager-travel)) 0;  }  .pager-link[rel~="next"] .pager-label .icon {    translate: var(--pager-travel) 0;  }  /* In a right-to-left page the same two drawings are turned round, and so is the way each moves. */  .pager-link:not([rel~="next"]) .pager-label:dir(rtl) .icon {    scale: -1 1;    translate: var(--pager-travel) 0;  }  .pager-link[rel~="next"] .pager-label:dir(rtl) .icon {    scale: -1 1;    translate: calc(-1 * var(--pager-travel)) 0;  }  /* The title of the page it leads to. */  .pager-title {    min-width: 0;    margin: 0;    color: var(--color-text-strong);    font-weight: var(--font-weight-control);    font-size: .9375rem;    line-height: 1.35;    text-wrap: balance;    overflow-wrap: anywhere;  }}