網站導覽

v2.1.0
網站導覽

底部導覽列

沿著畫面底部排列小螢幕應用程式的主要入口。

本頁內容

底部導覽列沿著畫面底部排列小螢幕應用程式的三到五個主要入口,放在拇指容易搆到的位置。每個項目上方是圖示,下方是簡短的標籤。目前的項目以介面前景色呈現,圖示背後襯著柔和的膠囊形底色;列內其餘部分維持中性色。導覽列採用霧面玻璃效果,頂端有一道細線,底部則避開主畫面指示器。

底部導覽列

<div class="well h(320) max-w(380) mx-auto overflow-y-auto">  <div class="grid gap-sm p-md">    <div class="sheet p-lg text-sm">Today</div>    <div class="sheet p-lg text-sm">Continue reading</div>    <div class="sheet p-lg text-sm">New this week</div>    <div class="sheet p-lg text-sm">From your library</div>  </div>  <nav class="tabbar" aria-label="Main">    <a class="tabbar-item" href="#" aria-current="page">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M4 16.25L4 8.5672A1.25 1.25 0 0 1 4.4269 7.6265L9.1769 3.4702A1.25 1.25 0 0 1 10.8231 3.4702L15.5731 7.6265A1.25 1.25 0 0 1 16 8.5672L16 16.25A1.25 1.25 0 0 1 14.75 17.5L5.25 17.5A1.25 1.25 0 0 1 4 16.25Z" /><path d="M8 17.5L8 13.5A1 1 0 0 1 9 12.5L11 12.5A1 1 0 0 1 12 13.5L12 17.5" />      </svg><span class="tabbar-label">Home</span>    </a>    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="8.75" cy="8.75" r="5.75" /><path d="M12.8159 12.8159L17.5 17.5" />      </svg><span class="tabbar-label">Search</span>    </a>    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.5 2.5L2.5 17.5" /><path d="M6.6667 5L6.6667 17.5" /><path d="M10.8333 4.1667L10.8333 17.5" /><path d="M14.1667 4.1667L18.3333 17.0833" />      </svg><span class="tabbar-label">Library</span>    </a>    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="10" cy="5.6" r="3" /><path d="M4 17.25V15.75C4 13.4 6.95 11.9 8.85 11.9H11.15C13.05 11.9 16 13.4 16 15.75V17.25" />      </svg><span class="tabbar-label">Profile</span>    </a>  </nav></div>
import HomeIcon from '@master/icons-react/native/20/soft/home'import SearchIcon from '@master/icons-react/native/20/soft/search'import LibraryIcon from '@master/icons-react/native/20/soft/library'import UserIcon from '@master/icons-react/native/20/soft/user'<div className="well h(320) max-w(380) mx-auto overflow-y-auto">  <div className="grid gap-sm p-md">    <div className="sheet p-lg text-sm">Today</div>    <div className="sheet p-lg text-sm">Continue reading</div>    <div className="sheet p-lg text-sm">New this week</div>    <div className="sheet p-lg text-sm">From your library</div>  </div>  <nav className="tabbar" aria-label="Main">    <a className="tabbar-item" href="#" aria-current="page">      <HomeIcon className="icon" /><span className="tabbar-label">Home</span>    </a>    <a className="tabbar-item" href="#">      <SearchIcon className="icon" /><span className="tabbar-label">Search</span>    </a>    <a className="tabbar-item" href="#">      <LibraryIcon className="icon" /><span className="tabbar-label">Library</span>    </a>    <a className="tabbar-item" href="#">      <UserIcon className="icon" /><span className="tabbar-label">Profile</span>    </a>  </nav></div>
<script>  import HomeIcon from '@master/icons-svelte/native/20/soft/home'  import SearchIcon from '@master/icons-svelte/native/20/soft/search'  import LibraryIcon from '@master/icons-svelte/native/20/soft/library'  import UserIcon from '@master/icons-svelte/native/20/soft/user'</script><div class="well h(320) max-w(380) mx-auto overflow-y-auto">  <div class="grid gap-sm p-md">    <div class="sheet p-lg text-sm">Today</div>    <div class="sheet p-lg text-sm">Continue reading</div>    <div class="sheet p-lg text-sm">New this week</div>    <div class="sheet p-lg text-sm">From your library</div>  </div>  <nav class="tabbar" aria-label="Main">    <a class="tabbar-item" href="#" aria-current="page">      <HomeIcon class="icon" /><span class="tabbar-label">Home</span>    </a>    <a class="tabbar-item" href="#">      <SearchIcon class="icon" /><span class="tabbar-label">Search</span>    </a>    <a class="tabbar-item" href="#">      <LibraryIcon class="icon" /><span class="tabbar-label">Library</span>    </a>    <a class="tabbar-item" href="#">      <UserIcon class="icon" /><span class="tabbar-label">Profile</span>    </a>  </nav></div>
<script setup>import HomeIcon from '@master/icons-vue/native/20/soft/home'import SearchIcon from '@master/icons-vue/native/20/soft/search'import LibraryIcon from '@master/icons-vue/native/20/soft/library'import UserIcon from '@master/icons-vue/native/20/soft/user'</script><template>  <div class="well h(320) max-w(380) mx-auto overflow-y-auto">    <div class="grid gap-sm p-md">      <div class="sheet p-lg text-sm">Today</div>      <div class="sheet p-lg text-sm">Continue reading</div>      <div class="sheet p-lg text-sm">New this week</div>      <div class="sheet p-lg text-sm">From your library</div>    </div>    <nav class="tabbar" aria-label="Main">      <a class="tabbar-item" href="#" aria-current="page">        <HomeIcon class="icon" /><span class="tabbar-label">Home</span>      </a>      <a class="tabbar-item" href="#">        <SearchIcon class="icon" /><span class="tabbar-label">Search</span>      </a>      <a class="tabbar-item" href="#">        <LibraryIcon class="icon" /><span class="tabbar-label">Library</span>      </a>      <a class="tabbar-item" href="#">        <UserIcon class="icon" /><span class="tabbar-label">Profile</span>      </a>    </nav>  </div></template>
捲動預覽,內容會從導覽列下方滑過。

導覽列透過 position: sticky 貼在捲動容器底部。如果應用程式框架本身不會整體捲動,就把導覽列放在捲動區域之後,外觀相同。

底部導覽列元件只定義列本身,在頁面各區域中的位置由版面配置決定。在頁面中,它接在主要區域之後;在固定式應用程式框架中,它放在頁尾。

#浮動

tabbar-floating 透過外距讓導覽列離開畫面邊緣,加上表面圓角與浮動陰影。

浮動

<div class="tray h(320) max-w(380) mx-auto p(0) overflow-y-auto">  <div class="grid gap-sm p-md">    <div class="sheet p-lg text-sm">Today</div>    <div class="sheet p-lg text-sm">Continue reading</div>    <div class="sheet p-lg text-sm">New this week</div>    <div class="sheet p-lg text-sm">From your library</div>  </div>  <nav class="tabbar tabbar-floating" aria-label="Main">    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M4 16.25L4 8.5672A1.25 1.25 0 0 1 4.4269 7.6265L9.1769 3.4702A1.25 1.25 0 0 1 10.8231 3.4702L15.5731 7.6265A1.25 1.25 0 0 1 16 8.5672L16 16.25A1.25 1.25 0 0 1 14.75 17.5L5.25 17.5A1.25 1.25 0 0 1 4 16.25Z" /><path d="M8 17.5L8 13.5A1 1 0 0 1 9 12.5L11 12.5A1 1 0 0 1 12 13.5L12 17.5" />      </svg><span class="tabbar-label">Home</span>    </a>    <a class="tabbar-item" href="#" aria-current="page">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="8.75" cy="8.75" r="5.75" /><path d="M12.8159 12.8159L17.5 17.5" />      </svg><span class="tabbar-label">Search</span>    </a>    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.5 2.5L2.5 17.5" /><path d="M6.6667 5L6.6667 17.5" /><path d="M10.8333 4.1667L10.8333 17.5" /><path d="M14.1667 4.1667L18.3333 17.0833" />      </svg><span class="tabbar-label">Library</span>    </a>    <a class="tabbar-item" href="#">      <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="10" cy="5.6" r="3" /><path d="M4 17.25V15.75C4 13.4 6.95 11.9 8.85 11.9H11.15C13.05 11.9 16 13.4 16 15.75V17.25" />      </svg><span class="tabbar-label">Profile</span>    </a>  </nav></div>
import HomeIcon from '@master/icons-react/native/20/soft/home'import SearchIcon from '@master/icons-react/native/20/soft/search'import LibraryIcon from '@master/icons-react/native/20/soft/library'import UserIcon from '@master/icons-react/native/20/soft/user'<div className="tray h(320) max-w(380) mx-auto p(0) overflow-y-auto">  <div className="grid gap-sm p-md">    <div className="sheet p-lg text-sm">Today</div>    <div className="sheet p-lg text-sm">Continue reading</div>    <div className="sheet p-lg text-sm">New this week</div>    <div className="sheet p-lg text-sm">From your library</div>  </div>  <nav className="tabbar tabbar-floating" aria-label="Main">    <a className="tabbar-item" href="#">      <HomeIcon className="icon" /><span className="tabbar-label">Home</span>    </a>    <a className="tabbar-item" href="#" aria-current="page">      <SearchIcon className="icon" /><span className="tabbar-label">Search</span>    </a>    <a className="tabbar-item" href="#">      <LibraryIcon className="icon" /><span className="tabbar-label">Library</span>    </a>    <a className="tabbar-item" href="#">      <UserIcon className="icon" /><span className="tabbar-label">Profile</span>    </a>  </nav></div>
<script>  import HomeIcon from '@master/icons-svelte/native/20/soft/home'  import SearchIcon from '@master/icons-svelte/native/20/soft/search'  import LibraryIcon from '@master/icons-svelte/native/20/soft/library'  import UserIcon from '@master/icons-svelte/native/20/soft/user'</script><div class="tray h(320) max-w(380) mx-auto p(0) overflow-y-auto">  <div class="grid gap-sm p-md">    <div class="sheet p-lg text-sm">Today</div>    <div class="sheet p-lg text-sm">Continue reading</div>    <div class="sheet p-lg text-sm">New this week</div>    <div class="sheet p-lg text-sm">From your library</div>  </div>  <nav class="tabbar tabbar-floating" aria-label="Main">    <a class="tabbar-item" href="#">      <HomeIcon class="icon" /><span class="tabbar-label">Home</span>    </a>    <a class="tabbar-item" href="#" aria-current="page">      <SearchIcon class="icon" /><span class="tabbar-label">Search</span>    </a>    <a class="tabbar-item" href="#">      <LibraryIcon class="icon" /><span class="tabbar-label">Library</span>    </a>    <a class="tabbar-item" href="#">      <UserIcon class="icon" /><span class="tabbar-label">Profile</span>    </a>  </nav></div>
<script setup>import HomeIcon from '@master/icons-vue/native/20/soft/home'import SearchIcon from '@master/icons-vue/native/20/soft/search'import LibraryIcon from '@master/icons-vue/native/20/soft/library'import UserIcon from '@master/icons-vue/native/20/soft/user'</script><template>  <div class="tray h(320) max-w(380) mx-auto p(0) overflow-y-auto">    <div class="grid gap-sm p-md">      <div class="sheet p-lg text-sm">Today</div>      <div class="sheet p-lg text-sm">Continue reading</div>      <div class="sheet p-lg text-sm">New this week</div>      <div class="sheet p-lg text-sm">From your library</div>    </div>    <nav class="tabbar tabbar-floating" aria-label="Main">      <a class="tabbar-item" href="#">        <HomeIcon class="icon" /><span class="tabbar-label">Home</span>      </a>      <a class="tabbar-item" href="#" aria-current="page">        <SearchIcon class="icon" /><span class="tabbar-label">Search</span>      </a>      <a class="tabbar-item" href="#">        <LibraryIcon class="icon" /><span class="tabbar-label">Library</span>      </a>      <a class="tabbar-item" href="#">        <UserIcon class="icon" /><span class="tabbar-label">Profile</span>      </a>    </nav>  </div></template>

#使用時機

當使用者一天中會頻繁切換幾個同等重要的目的地時,使用底部導覽列。同一頁面中的不同檢視請使用分頁標籤;在寬螢幕上,請將同樣的入口放進導覽列或導覽區。每個標籤請限用一個詞。空間不足時,標籤會以刪節號截斷,以免擠壓相鄰項目。

#無障礙

  • 導覽列使用帶有標籤的 <nav>,每個項目都是連結,並在目前的項目上加上 aria-current="page"。如果項目在原地切換面板,請使用 role="tablist",並搭配 role="tab" 和 aria-selected。兩種目前狀態的外觀相同。
  • 每個項目都要保留標籤。單看圖示得猜意思,圖示下方的文字才是項目的名稱。
  • 每個項目至少高 56px,並平分可用寬度,遠超過觸控目標所需的 44px。
  • 導覽列透過 env(safe-area-inset-bottom) 在項目下方留出空間。請在檢視區的 meta 標記中設定 viewport-fit=cover,底部安全區域的內距才會生效。

#類別

類別說明
tabbar將分頁列樣式套用在有標籤的 nav 上。分頁列會黏附在底部,採毛玻璃樣式,各導覽項目等寬
tabbar-floating浮動分頁列與邊緣留有間距,沿用表面樣式的圓角,並加上浮動陰影搭配 tabbar 使用
tabbar-item導覽項目使用連結或按鈕,圖示放在 tabbar-label 上方
tabbar-label圖示下方的文字限一行,空間不足時以省略號截斷,以免擠壓相鄰項目

#自訂屬性

屬性預設值說明
--tabbar-height3.5rem項目的最小高度
--tabbar-colorvar(--color-surface-base)面板的色調

#原始碼

@master/ui/components/tabbar.css
/* * Tab bar: the few main destinations of a small-screen app, along the bottom edge under the thumb. * Each item is an icon over a short label. The current one is in ink and its icon rests on a soft pill. * The bar is a pane of frosted glass with a hairline above it, and it keeps clear of the home indicator. */@layer components.ui {  .tabbar {    --tabbar-height: 3.5rem;    --tabbar-color: var(--color-surface-base);    position: sticky;    bottom: 0;    z-index: 20;    display: grid;    grid-auto-columns: minmax(0, 1fr);    grid-auto-flow: column;    min-width: 0;    margin: 0;    /* Clear of the home indicator below and, on a phone turned on its side, of the notch at either end. */    padding: 0 max(.25rem, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(.25rem, env(safe-area-inset-left, 0px));    background: color-mix(in oklab, var(--tabbar-color) 78%, transparent);    box-shadow: inset 0 .5px 0 var(--color-line-strong);    backdrop-filter: blur(16px) saturate(1.7);    list-style: none;    /* Floating: a bar lifted off the edge, with the corner of a surface. */    &.tabbar-floating {      --tabbar-color: var(--color-surface-floating);      bottom: max(.75rem, env(safe-area-inset-bottom, 0px));      /* Its sides keep clear of a phone's notch too, turned on its side, as the edge bar's padding does. */      margin: .75rem max(.75rem, env(safe-area-inset-right, 0px)) .75rem max(.75rem, env(safe-area-inset-left, 0px));      padding: 0 .25rem;      border-radius: calc(var(--radius-surface) * var(--corner-scale) + 4px);      corner-shape: var(--corner-shape);      box-shadow: var(--shadow-floating);    }    @media (prefers-reduced-transparency: reduce) {      background: var(--tabbar-color);      backdrop-filter: none;    }    /* An outline, not a border: the bar keeps its height and the floating bar its corner. */    @media (forced-colors: active) {      outline: 1px solid CanvasText;      outline-offset: -1px;      background: Canvas;    }  }  .tabbar-item {    --icon-size: 1.25rem;    position: relative;    display: flex;    flex-direction: column;    align-items: center;    justify-content: center;    gap: .25rem;    min-width: 0;    min-height: var(--tabbar-height);    margin: 0;    padding: .375rem .25rem;    border: 0;    background: transparent;    color: var(--color-text-muted);    font: var(--font-weight-control) .6875rem/1 var(--font-family-sans);    font-feature-settings: inherit;    letter-spacing: .005em;    text-decoration: none;    cursor: pointer;    touch-action: manipulation;    isolation: isolate;    -webkit-tap-highlight-color: transparent;    transition: color var(--duration-quick) var(--easing-glide);    user-select: none;    -webkit-user-select: none;    /*     * The pill behind the icon: 56 by 28, centered on the icon's row, which stands half the gap and the 11px     * label above the item's middle. It grows in from a little smaller.     */    &::before {      content: '';      position: absolute;      top: calc(50% - (.25rem + .6875rem) / 2 - .875rem);      left: calc(50% - 1.75rem);      z-index: -1;      width: 3.5rem;      height: 1.75rem;      border-radius: 999px;      background: var(--color-surface-chip);      box-shadow: inset 0 0 0 .5px var(--color-line-hair);      opacity: 0;      scale: .8 .9;      transition-property: opacity, scale;      transition-duration: var(--duration-base);      transition-timing-function: var(--easing-glide);    }    @media (hover: hover) {      &:hover {        color: var(--color-text-strong);      }    }    &:is([aria-current="page"], [aria-selected="true"]) {      color: var(--color-text-strong);      &::before {        opacity: 1;        scale: 1;      }    }    &:active:not(:disabled, [aria-disabled="true"])::before {      opacity: 1;      scale: .94;      transition-duration: var(--duration-press);    }    &:focus-visible {      @apply --focus-ring;      outline-offset: -4px;      border-radius: calc(var(--radius-control) * var(--corner-scale));      corner-shape: var(--corner-shape);    }    /* The pill fades in without growing, and a press does not shrink it. */    @media (prefers-reduced-motion: reduce) {      &::before, &:active:not(:disabled, [aria-disabled="true"])::before {        scale: none;      }    }    @media (forced-colors: active) {      &:is([aria-current="page"], [aria-selected="true"]) {        color: Highlight;      }    }    &:is(:disabled, [aria-disabled="true"]) {      color: var(--color-text-disabled);      cursor: not-allowed;      @media (forced-colors: active) {        color: GrayText;      }    }  }  /* The word under the icon: one line, cut with an ellipsis before it pushes its neighbors. */  .tabbar-label {    overflow: hidden;    max-width: 100%;    /*     * A line as tall as the letters would clip the descenders of y, g and p at the ellipsis's edge. The line is a     * quarter taller and the margin takes that back, so the item and the pill above it keep their places.     */    margin-block: -.0859375rem;    line-height: 1.25;    text-overflow: ellipsis;    white-space: nowrap;  }}