导航
底部标签栏
在小屏应用的底部排列主要入口。
本页内容
标签栏位于小屏应用底部拇指易触及的位置,提供三到五个主要入口。每项的图标下方都有简短标签。当前项以墨色显示,图标衬有柔和的胶囊形底,其余部分保持无彩色。栏体采用磨砂玻璃材质,顶部有一条细线,底部避开主屏幕指示条。
标签栏
<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-height | 3.5rem | 导航项的最小高度 |
--tabbar-color | var(--color-surface-base) | 磨砂玻璃背景的着色 |