组件详解#11:底部固定导航,拇指热区的黄金4厘米 | Component Deep Dive #11: Bottom Nav — The 4cm Gold Zone for Your User's Thumb

本文组件来自 Web Component Dictionary v2.0 · 网页组件活字典,83组件/8分类/中英双语/实时预览/单文件无依赖。
在线体验:wdsega.github.io/web-components | 购买完整版:payhip.com/b/S9pj2 ¥9.99


你的用户只有一根拇指,而你给了他一排按钮在屏幕最顶上

打开手机,看看你最常用的 App——微信、抖音、淘宝、支付宝。它们的导航在哪?底部。这不是巧合,是人体工学。

iPhone 从 4 寸涨到 6.7 寸,屏幕顶部离拇指越来越远。Josh Clark 在《Designing for Touch》里画过一个热区图:拇指自然握持时,最舒适的操作区域是屏幕底部 4 厘米。把导航放到顶部,等于让你的用户每切换一次页面就做一次手指拉伸运动。

底部固定导航(Bottom Nav)是这个问题的标准答案。

组件是什么

Web Component Dictionary v2.0 中的底部导航是一个纯 CSS + JS 实现:固定在视口底部的横排导航栏,每个项是图标+文字,当前页面高亮。

核心特征:

  • position: fixed; bottom: 0 吸底
  • 等分宽度(flex 布局)
  • 图标+文字的组合项
  • 活跃态颜色+缩放动画

代码拆解

HTML

<nav class="bottom-nav">
  <a href="#" class="bottom-nav-item active">
    <span class="bottom-nav-icon">🏠</span>
    <span class="bottom-nav-label">Home</span>
  </a>
  <a href="#" class="bottom-nav-item">
    <span class="bottom-nav-icon">🔍</span>
    <span class="bottom-nav-label">Search</span>
  </a>
  <a href="#" class="bottom-nav-item">
    <span class="bottom-nav-icon">❤️</span>
    <span class="bottom-nav-label">Favorites</span>
  </a>
  <a href="#" class="bottom-nav-item">
    <span class="bottom-nav-icon">👤</span>
    <span class="bottom-nav-label">Profile</span>
  </a>
</nav>

CSS

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: #1a1a2e;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index: 1000;
  border-top: 1px solid #333;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  color: #777;
  font-size: 10px;
  padding: 6px 16px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.bottom-nav-item.active {
  color: #e94560;
}

.bottom-nav-icon {
  font-size: 20px;
  line-height: 1;
}

.bottom-nav-label {
  font-size: 11px;
  font-weight: 500;
}

JS:点击切换

document.querySelectorAll('.bottom-nav-item').forEach(item => {
  item.addEventListener('click', function(e) {
    e.preventDefault();
    document.querySelectorAll('.bottom-nav-item').forEach(i => i.classList.remove('active'));
    this.classList.add('active');
  });
});

关键技术点深挖

env(safe-area-inset-bottom) — 刘海屏救星

iPhone X 之后的全面屏底部有一条 Home Indicator 横条。不加 safe-area-inset-bottom,你的导航栏会被横条盖住或者紧贴横条,看起来像被切了一刀。

env(safe-area-inset-bottom) 会自动读取系统的安全区高度(通常是 34px),给导航栏底部加相应的 padding。同时需要在 <head> 里加:

<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">

viewport-fit=cover 告诉浏览器”我知道有刘海/横条,请给我全屏,我自己处理安全区”。

最多 5 项,3-5 最佳

Material Design 指南建议底部导航 3-5 个项。超过 5 个,每个项太窄,点击精度下降。如果必须放更多功能,考虑:

  • 中间放一个大按钮(”发布”/”+”),让它突出
  • 最后一个项改成”更多”→ 弹出菜单

图标+文字,缺一不可

纯图标导航对新手不友好(那个心形是”喜欢”还是”收藏”?)。纯文字太枯燥。图标+文字的组合识别速度最快。

常见坑点

坑1:忘记给页面底部加 padding

导航栏用 position: fixed; bottom: 0,会盖住页面最底部的内容。需要给 <body> 或主内容容器加 padding-bottom: 70px(大约导航栏高度+安全区)。

坑2:iOS Safari 底部工具栏干扰

iOS Safari 在页面底部有自己的导航栏。如果页面可滚动,用户上滑时 Safari 工具栏会收起→你的 bottom nav 变成悬浮在半空中→下面露出奇怪的空白。解决方案:给 body 加 min-height: 100dvh,使用动态视口高度单位。

坑3:桌面端怎么办?

桌面端没有拇指热区的问题。建议用 @media (min-width: 768px) 把底部导航改成侧边栏或顶部导航,避免桌面用户对着屏幕底部一排按钮感到困惑。

完整可复制代码

(从 Web Component Dictionary v2.0 复制完整实现,单文件即用)

变体拓展

  1. 中间突出按钮:中间项比其他项高出一截,像抖音的”+”发布按钮,视觉重心强化
  2. Badge 角标:在图标右上角加小红点或数字,显示未读消息数
  3. 流体指示器:活跃项下加一个会滑动的圆角条,切换时平滑移动到目标项下方

本文组件来自 Web Component Dictionary v2.0 — 83个开箱即用的网页组件,导航/表单/数据展示/多媒体等8大分类,中英双语,实时预览,单文件无依赖。
🔗 在线体验:wdsega.github.io/web-components
🛒 购买完整版源码(¥9.99 一次性买断):payhip.com/b/S9pj2


Component Deep Dive #11: Bottom Nav — The 4cm Gold Zone for Your User’s Thumb

One Thumb, One Row of Buttons at the Very Top

Open your most-used apps — WeChat, TikTok, Taobao, Alipay. Where’s the navigation? At the bottom. This isn’t coincidence; it’s ergonomics.

As iPhones grew from 4” to 6.7”, the screen top moved further from the thumb. Josh Clark’s heat maps in Designing for Touch show the sweet spot: the bottom 4cm of the screen in natural grip. Putting navigation at the top forces a finger-stretch workout with every tab switch.

Bottom Nav is the standard answer.

What It Is

Fixed horizontal nav bar at the viewport bottom, icon + label per item, with active state highlighting.

Code Breakdown

HTML: <nav> wrapping <a> items, each with icon span and label span.

CSS: position: fixed; bottom: 0 pins it. env(safe-area-inset-bottom) handles notched screens. Flex layout with equal spacing. Active state switches color and optionally scales.

JS: Click handler toggles .active class.

Key Insight: env(safe-area-inset-bottom)

Since iPhone X, the home indicator bar overlaps the bottom of the screen. Without safe-area-inset-bottom, your nav bar gets clipped. This CSS env variable automatically reads system safe area height (~34px). Must pair with <meta viewport-fit=cover> in <head>.

Rules of Thumb (Literally)

  • 3-5 items max: Material Design recommendation. Above 5, tap targets get too narrow.
  • Icon + label, always: Icons alone confuse new users. Text alone is boring. Combined is fastest recognition.
  • Mind the content behind: Fixed bottom nav covers content. Add padding-bottom: ~70px to your main container.
  • Desktop? Use @media (min-width: 768px) to switch to sidebar or top nav. Bottom nav makes no sense with a mouse.

Common Pitfalls

  • iOS Safari toolbar fight: Scrolling up hides the address bar, shifting your bottom nav position. Use min-height: 100dvh for dynamic viewport height.
  • Forgetting content padding: Fixed nav overlaps your last content element.

Variants

  • Center-prominent button: Middle item taller than others (like TikTok’s + button)
  • Badge indicators: Red dots or numbers on icons for unread counts
  • Fluid indicator: A sliding pill under the active item that animates between positions

This component is from Web Component Dictionary v2.0 — 83 ready-to-use web components across 8 categories. Bilingual, live preview, single-file, zero dependencies.
🔗 Live demo: wdsega.github.io/web-components
🛒 Buy full source code ($9.99 one-time): payhip.com/b/S9pj2



← 返回首页