網站導覽
目錄
將頁面標題列成連結,並透過 CSS 標記目前在檢視區中的章節。
本頁內容
目錄將頁面各節的標題列成一欄連結,旁邊有一條細線。目前在檢視區中的章節連結會使用主文字色,細線上的標記則會在連結之間滑動。瀏覽器支援 scroll-target-group 時,會隨捲動位置自動更新標記,目標位於檢視區中的連結會符合 :target-current,無須觀察器或腳本。
目錄
<div class="grid grid-cols(2) gap-lg"> <div class="h(240) overflow-y-auto scroll-area text-sm leading-md fg-text-body"> <h3 class="m(0) fg-text-strong" id="toc-install">Install</h3> <p> Add the package and import it after the preset. The stylesheet has no build step of its own. </p> <p>It ships as plain CSS files, one per component.</p> <h3 class="fg-text-strong" id="toc-theme">Theme</h3> <p> Moonstone and obsidian share one set of tokens. Override a token and every component follows. </p> <p>The brand color is one token.</p> <h3 class="fg-text-strong" id="toc-corners">Corners</h3> <p> Corners turn with continuous curvature where the browser can draw them, and nest by their inset. </p> <p>Elsewhere they are circular.</p> <h3 class="fg-text-strong" id="toc-motion">Motion</h3> <p> One easing family. Interaction is quick, explanation calm, and reduced motion keeps the fade. </p> <p class="mb(160)">That is the whole system.</p> </div> <nav class="toc self-start" aria-label="On this page"> <p class="toc-title">On this page</p> <ul class="toc-list"> <li><a class="toc-link" href="#toc-install">Install</a></li> <li><a class="toc-link" href="#toc-theme">Theme</a></li> <li><a class="toc-link" href="#toc-corners">Corners</a></li> <li><a class="toc-link" href="#toc-motion">Motion</a></li> </ul> </nav></div><div className="grid grid-cols(2) gap-lg"> <div className="h(240) overflow-y-auto scroll-area text-sm leading-md fg-text-body"> <h3 className="m(0) fg-text-strong" id="toc-install">Install</h3> <p> Add the package and import it after the preset. The stylesheet has no build step of its own. </p> <p>It ships as plain CSS files, one per component.</p> <h3 className="fg-text-strong" id="toc-theme">Theme</h3> <p> Moonstone and obsidian share one set of tokens. Override a token and every component follows. </p> <p>The brand color is one token.</p> <h3 className="fg-text-strong" id="toc-corners">Corners</h3> <p> Corners turn with continuous curvature where the browser can draw them, and nest by their inset. </p> <p>Elsewhere they are circular.</p> <h3 className="fg-text-strong" id="toc-motion">Motion</h3> <p> One easing family. Interaction is quick, explanation calm, and reduced motion keeps the fade. </p> <p className="mb(160)">That is the whole system.</p> </div> <nav className="toc self-start" aria-label="On this page"> <p className="toc-title">On this page</p> <ul className="toc-list"> <li><a className="toc-link" href="#toc-install">Install</a></li> <li><a className="toc-link" href="#toc-theme">Theme</a></li> <li><a className="toc-link" href="#toc-corners">Corners</a></li> <li><a className="toc-link" href="#toc-motion">Motion</a></li> </ul> </nav></div><div class="grid grid-cols(2) gap-lg"> <div class="h(240) overflow-y-auto scroll-area text-sm leading-md fg-text-body"> <h3 class="m(0) fg-text-strong" id="toc-install">Install</h3> <p> Add the package and import it after the preset. The stylesheet has no build step of its own. </p> <p>It ships as plain CSS files, one per component.</p> <h3 class="fg-text-strong" id="toc-theme">Theme</h3> <p> Moonstone and obsidian share one set of tokens. Override a token and every component follows. </p> <p>The brand color is one token.</p> <h3 class="fg-text-strong" id="toc-corners">Corners</h3> <p> Corners turn with continuous curvature where the browser can draw them, and nest by their inset. </p> <p>Elsewhere they are circular.</p> <h3 class="fg-text-strong" id="toc-motion">Motion</h3> <p> One easing family. Interaction is quick, explanation calm, and reduced motion keeps the fade. </p> <p class="mb(160)">That is the whole system.</p> </div> <nav class="toc self-start" aria-label="On this page"> <p class="toc-title">On this page</p> <ul class="toc-list"> <li><a class="toc-link" href="#toc-install">Install</a></li> <li><a class="toc-link" href="#toc-theme">Theme</a></li> <li><a class="toc-link" href="#toc-corners">Corners</a></li> <li><a class="toc-link" href="#toc-motion">Motion</a></li> </ul> </nav></div><template> <div class="grid grid-cols(2) gap-lg"> <div class="h(240) overflow-y-auto scroll-area text-sm leading-md fg-text-body"> <h3 class="m(0) fg-text-strong" id="toc-install">Install</h3> <p> Add the package and import it after the preset. The stylesheet has no build step of its own. </p> <p>It ships as plain CSS files, one per component.</p> <h3 class="fg-text-strong" id="toc-theme">Theme</h3> <p> Moonstone and obsidian share one set of tokens. Override a token and every component follows. </p> <p>The brand color is one token.</p> <h3 class="fg-text-strong" id="toc-corners">Corners</h3> <p> Corners turn with continuous curvature where the browser can draw them, and nest by their inset. </p> <p>Elsewhere they are circular.</p> <h3 class="fg-text-strong" id="toc-motion">Motion</h3> <p> One easing family. Interaction is quick, explanation calm, and reduced motion keeps the fade. </p> <p class="mb(160)">That is the whole system.</p> </div> <nav class="toc self-start" aria-label="On this page"> <p class="toc-title">On this page</p> <ul class="toc-list"> <li><a class="toc-link" href="#toc-install">Install</a></li> <li><a class="toc-link" href="#toc-theme">Theme</a></li> <li><a class="toc-link" href="#toc-corners">Corners</a></li> <li><a class="toc-link" href="#toc-motion">Motion</a></li> </ul> </nav> </div></template>捲動文字,標記就會跟著目前在檢視區中的章節移動。瀏覽器不支援 scroll-target-group 時,要等腳本設定 aria-current 才會顯示標記。
#層級
在清單項目內放入 toc-list,即可加入下一層目錄。各層共用同一條細線,子層連結會縮排一級。一頁用兩層就夠了,需要第三層時,可以考慮拆成多個頁面。
層級
<nav class="toc max-w(220)" aria-label="On this page"> <ul class="toc-list"> <li><a class="toc-link" href="#">Overview</a></li> <li> <a class="toc-link" href="#" aria-current="true">Theme</a> <ul class="toc-list"> <li><a class="toc-link" href="#">Surfaces</a></li> <li><a class="toc-link" href="#">Lines and shadows</a></li> <li><a class="toc-link" href="#">The brand color</a></li> </ul> </li> <li><a class="toc-link" href="#">Accessibility</a></li> </ul></nav><nav className="toc max-w(220)" aria-label="On this page"> <ul className="toc-list"> <li><a className="toc-link" href="#">Overview</a></li> <li> <a className="toc-link" href="#" aria-current="true">Theme</a> <ul className="toc-list"> <li><a className="toc-link" href="#">Surfaces</a></li> <li><a className="toc-link" href="#">Lines and shadows</a></li> <li><a className="toc-link" href="#">The brand color</a></li> </ul> </li> <li><a className="toc-link" href="#">Accessibility</a></li> </ul></nav><nav class="toc max-w(220)" aria-label="On this page"> <ul class="toc-list"> <li><a class="toc-link" href="#">Overview</a></li> <li> <a class="toc-link" href="#" aria-current="true">Theme</a> <ul class="toc-list"> <li><a class="toc-link" href="#">Surfaces</a></li> <li><a class="toc-link" href="#">Lines and shadows</a></li> <li><a class="toc-link" href="#">The brand color</a></li> </ul> </li> <li><a class="toc-link" href="#">Accessibility</a></li> </ul></nav><template> <nav class="toc max-w(220)" aria-label="On this page"> <ul class="toc-list"> <li><a class="toc-link" href="#">Overview</a></li> <li> <a class="toc-link" href="#" aria-current="true">Theme</a> <ul class="toc-list"> <li><a class="toc-link" href="#">Surfaces</a></li> <li><a class="toc-link" href="#">Lines and shadows</a></li> <li><a class="toc-link" href="#">The brand color</a></li> </ul> </li> <li><a class="toc-link" href="#">Accessibility</a></li> </ul> </nav></template>#自行標記目前章節
在連結上設定 aria-current="true",會呈現與 :target-current 相同的狀態。靜態清單可以由伺服器設定。瀏覽器不支援捲動目標群組時,可以用 IntersectionObserver 設定。兩者並用時,都會標記目前在檢視區中的章節,因此結果一致。
#無障礙
- 目錄清單使用
<nav>,並加上「本頁內容」之類的標籤,方便使用者透過頁面地標找到目錄,並與主要導覽區分。 - 連結透過
id指向標題。如果導覽列黏附在捲動容器上方,請為容器設定scroll-padding-top,避免跳轉後標題被導覽列遮住。 - 目前的連結會改用主文字色,旁邊會出現同色的 1.5px 寬標記,兩種提示都無須靠色相來辨識。啟用減少動態效果時,標記會直接移到新位置。
#類別
| 類別 | 說明 |
|---|---|
toc | 容器使用 nav,並加上「本頁內容」等標籤,作為捲動目標群組 |
toc-title | 清單上方的說明文字 |
toc-list | 沿著細導引線排列的連結清單。巢狀在清單項目中的 toc-list 會共用導引線,連結再縮排一級 |
toc-link | 透過 id 連到標題。對應目前可見區段的連結會使用醒目的文字色,並在導引線上加上標記 |
#自訂屬性
| 屬性 | 預設值 | 說明 |
|---|---|---|
--toc-indent | .875rem | 導引線與文字的間距,也是每一層的縮排量 |