导航

v2.1.0
网站页面

圣杯布局

页眉与页脚之间设有三栏,中间的正文栏在源码中排在两侧栏之前。

圣杯布局是最早有专门名称的页面布局。它由页眉、三栏和页脚组成,中栏占据两侧边栏留出的空间,三栏都与最高的一栏等高,主要内容在源码中排在三栏之首。这个布局曾是个持续了十五年的难题。它就是启用了所有可选区域的应用框架。

圣杯布局

<div class="shell bg-surface-base fg-text-body text-sm" style="--shell-sidebar: 13rem; --shell-aside: 15rem">  <header class="navbar shell-header bb(1) bb-solid b-line-hair" style="--navbar-padding-x: 1.25rem">    <button type="button" class="btn btn-quiet btn-square btn-sm shell-toggle" commandfor="hg-nav" command="show-modal" aria-label="Open navigation">      <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="M3 5.5L13 5.5" /><path d="M3 10.5L13 10.5" />      </svg>    </button>    <a class="navbar-brand" href="#">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <circle cx="8" cy="8" r="6" /><path d="M8 4.3333A3.6667 3.6667 0 0 1 8 11.6667Z" fill="currentColor" stroke="none" />      </svg>Atlas    </a>    <div class="navbar-end">      <button type="button" class="btn btn-primary btn-sm">Subscribe</button>    </div>  </header>  <main class="shell-main">    <article class="flex flex-col gap-md max-w(640) mx-auto px(20) py-xl">      <p class="eyebrow">Engineering</p>      <h1 class="heading heading-2xl">How we cut cold builds by forty seconds</h1>      <p class="lead">        Most of a cold build was spent fetching what the last build had already fetched. We stopped throwing it away.      </p>      <p class="m(0) leading-md">        A build starts from an empty machine. For years that was a feature: nothing left over from last time could break this time. It also meant every build downloaded the same two hundred megabytes of dependencies before doing any work of its own.      </p>      <p class="m(0) leading-md">        The fix was not a faster download. It was to key a cache by the lockfile, restore it before the install step, and let the package manager find that it had nothing to do. The install step now takes about three seconds when nothing changed, which is most of the time.      </p>      <p class="m(0) leading-md">        The main column is first in the source, before both side columns. The grid places each region by its class, so the order a screen reader meets them in is the order of importance, not the order on screen.      </p>      <p class="m(0) leading-md">        We measured for a month before turning it on for everyone. Median cold build time went from 96 seconds to 55, and the slowest tenth improved the most, because they had the most to download.      </p>    </article>  </main>  <div class="shell-sidebar p-sm bxe(1) bxe-solid b-line-hair">    <nav class="nav" aria-label="Sections">      <a class="nav-item" href="#">Latest</a>      <a class="nav-item" href="#" aria-current="page">Engineering</a>      <a class="nav-item" href="#">Product</a>      <a class="nav-item" href="#">Company</a>      <a class="nav-item" href="#">Customers</a>    </nav>  </div>  <aside class="shell-aside gap-md px-lg py-xl bxs(1) bxs-solid b-line-hair" aria-labelledby="hg-related">    <h2 class="eyebrow" id="hg-related">More from engineering</h2>    <ul class="flex flex-col gap-md m(0) p(0)">      <li class="flex">        <a class="link link-quiet fg-text-strong" href="#">Preview comments, pinned to elements</a>      </li>      <li class="flex">        <a class="link link-quiet fg-text-strong" href="#">          A dashboard you can drive from the keyboard        </a>      </li>      <li class="flex">        <a class="link link-quiet fg-text-strong" href="#">Why a deployment is immutable</a>      </li>    </ul>  </aside>  <footer class="shell-footer bt(1) bt-solid b-line-hair">    <div class="flex flex-wrap items-center justify-between gap-sm px(20) py-lg text-xs fg-text-muted">      <span>© 2026 Atlas Labs</span>      <nav class="flex flex-wrap gap-lg" aria-label="Footer">        <a class="link link-quiet" href="#">Privacy</a>        <a class="link link-quiet" href="#">Terms</a>        <a class="link link-quiet" href="#">RSS</a>      </nav>    </div>  </footer>  <dialog class="dialog dialog-drawer dialog-drawer-start" id="hg-nav" closedby="any" aria-label="Navigation">    <div class="dialog-body">      <nav class="nav" aria-label="Sections, in the drawer">        <a class="nav-item" href="#">Latest</a>        <a class="nav-item" href="#" aria-current="page">Engineering</a>        <a class="nav-item" href="#">Product</a>        <a class="nav-item" href="#">Company</a>        <a class="nav-item" href="#">Customers</a>      </nav>    </div>    <button type="button" class="btn btn-quiet btn-square btn-sm dialog-close" commandfor="hg-nav" command="close" aria-label="Close navigation">      <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="M4 4L12 12" /><path d="M4 12L12 4" />      </svg>    </button>  </dialog></div>
import MenuIcon from '@master/icons-react/native/16/soft/menu'import ContrastIcon from '@master/icons-react/native/16/soft/contrast'import XIcon from '@master/icons-react/native/16/soft/x'<div className="shell bg-surface-base fg-text-body text-sm" style={{ '--shell-sidebar': '13rem', '--shell-aside': '15rem' } as React.CSSProperties}>  <header className="navbar shell-header bb(1) bb-solid b-line-hair" style={{ '--navbar-padding-x': '1.25rem' } as React.CSSProperties}>    <button type="button" className="btn btn-quiet btn-square btn-sm shell-toggle" {...{ commandfor: 'hg-nav', command: 'show-modal' }} aria-label="Open navigation">      <MenuIcon className="icon" />    </button>    <a className="navbar-brand" href="#"><ContrastIcon className="icon" />Atlas</a>    <div className="navbar-end">      <button type="button" className="btn btn-primary btn-sm">Subscribe</button>    </div>  </header>  <main className="shell-main">    <article className="flex flex-col gap-md max-w(640) mx-auto px(20) py-xl">      <p className="eyebrow">Engineering</p>      <h1 className="heading heading-2xl">How we cut cold builds by forty seconds</h1>      <p className="lead">        Most of a cold build was spent fetching what the last build had already fetched. We stopped throwing it away.      </p>      <p className="m(0) leading-md">        A build starts from an empty machine. For years that was a feature: nothing left over from last time could break this time. It also meant every build downloaded the same two hundred megabytes of dependencies before doing any work of its own.      </p>      <p className="m(0) leading-md">        The fix was not a faster download. It was to key a cache by the lockfile, restore it before the install step, and let the package manager find that it had nothing to do. The install step now takes about three seconds when nothing changed, which is most of the time.      </p>      <p className="m(0) leading-md">        The main column is first in the source, before both side columns. The grid places each region by its class, so the order a screen reader meets them in is the order of importance, not the order on screen.      </p>      <p className="m(0) leading-md">        We measured for a month before turning it on for everyone. Median cold build time went from 96 seconds to 55, and the slowest tenth improved the most, because they had the most to download.      </p>    </article>  </main>  <div className="shell-sidebar p-sm bxe(1) bxe-solid b-line-hair">    <nav className="nav" aria-label="Sections">      <a className="nav-item" href="#">Latest</a>      <a className="nav-item" href="#" aria-current="page">Engineering</a>      <a className="nav-item" href="#">Product</a>      <a className="nav-item" href="#">Company</a>      <a className="nav-item" href="#">Customers</a>    </nav>  </div>  <aside className="shell-aside gap-md px-lg py-xl bxs(1) bxs-solid b-line-hair" aria-labelledby="hg-related">    <h2 className="eyebrow" id="hg-related">More from engineering</h2>    <ul className="flex flex-col gap-md m(0) p(0)">      <li className="flex">        <a className="link link-quiet fg-text-strong" href="#">          Preview comments, pinned to elements        </a>      </li>      <li className="flex">        <a className="link link-quiet fg-text-strong" href="#">          A dashboard you can drive from the keyboard        </a>      </li>      <li className="flex">        <a className="link link-quiet fg-text-strong" href="#">Why a deployment is immutable</a>      </li>    </ul>  </aside>  <footer className="shell-footer bt(1) bt-solid b-line-hair">    <div className="flex flex-wrap items-center justify-between gap-sm px(20) py-lg text-xs fg-text-muted">      <span>© 2026 Atlas Labs</span>      <nav className="flex flex-wrap gap-lg" aria-label="Footer">        <a className="link link-quiet" href="#">Privacy</a>        <a className="link link-quiet" href="#">Terms</a>        <a className="link link-quiet" href="#">RSS</a>      </nav>    </div>  </footer>  <dialog className="dialog dialog-drawer dialog-drawer-start" id="hg-nav" closedby="any" aria-label="Navigation">    <div className="dialog-body">      <nav className="nav" aria-label="Sections, in the drawer">        <a className="nav-item" href="#">Latest</a>        <a className="nav-item" href="#" aria-current="page">Engineering</a>        <a className="nav-item" href="#">Product</a>        <a className="nav-item" href="#">Company</a>        <a className="nav-item" href="#">Customers</a>      </nav>    </div>    <button type="button" className="btn btn-quiet btn-square btn-sm dialog-close" {...{ commandfor: 'hg-nav', command: 'close' }} aria-label="Close navigation">      <XIcon className="icon" />    </button>  </dialog></div>
<script>  import MenuIcon from '@master/icons-svelte/native/16/soft/menu'  import ContrastIcon from '@master/icons-svelte/native/16/soft/contrast'  import XIcon from '@master/icons-svelte/native/16/soft/x'</script><div class="shell bg-surface-base fg-text-body text-sm" style="--shell-sidebar: 13rem; --shell-aside: 15rem">  <header class="navbar shell-header bb(1) bb-solid b-line-hair" style="--navbar-padding-x: 1.25rem">    <button type="button" class="btn btn-quiet btn-square btn-sm shell-toggle" commandfor="hg-nav" command="show-modal" aria-label="Open navigation">      <MenuIcon class="icon" />    </button>    <a class="navbar-brand" href="#"><ContrastIcon class="icon" />Atlas</a>    <div class="navbar-end">      <button type="button" class="btn btn-primary btn-sm">Subscribe</button>    </div>  </header>  <main class="shell-main">    <article class="flex flex-col gap-md max-w(640) mx-auto px(20) py-xl">      <p class="eyebrow">Engineering</p>      <h1 class="heading heading-2xl">How we cut cold builds by forty seconds</h1>      <p class="lead">        Most of a cold build was spent fetching what the last build had already fetched. We stopped throwing it away.      </p>      <p class="m(0) leading-md">        A build starts from an empty machine. For years that was a feature: nothing left over from last time could break this time. It also meant every build downloaded the same two hundred megabytes of dependencies before doing any work of its own.      </p>      <p class="m(0) leading-md">        The fix was not a faster download. It was to key a cache by the lockfile, restore it before the install step, and let the package manager find that it had nothing to do. The install step now takes about three seconds when nothing changed, which is most of the time.      </p>      <p class="m(0) leading-md">        The main column is first in the source, before both side columns. The grid places each region by its class, so the order a screen reader meets them in is the order of importance, not the order on screen.      </p>      <p class="m(0) leading-md">        We measured for a month before turning it on for everyone. Median cold build time went from 96 seconds to 55, and the slowest tenth improved the most, because they had the most to download.      </p>    </article>  </main>  <div class="shell-sidebar p-sm bxe(1) bxe-solid b-line-hair">    <nav class="nav" aria-label="Sections">      <a class="nav-item" href="#">Latest</a>      <a class="nav-item" href="#" aria-current="page">Engineering</a>      <a class="nav-item" href="#">Product</a>      <a class="nav-item" href="#">Company</a>      <a class="nav-item" href="#">Customers</a>    </nav>  </div>  <aside class="shell-aside gap-md px-lg py-xl bxs(1) bxs-solid b-line-hair" aria-labelledby="hg-related">    <h2 class="eyebrow" id="hg-related">More from engineering</h2>    <ul class="flex flex-col gap-md m(0) p(0)">      <li class="flex">        <a class="link link-quiet fg-text-strong" href="#">Preview comments, pinned to elements</a>      </li>      <li class="flex">        <a class="link link-quiet fg-text-strong" href="#">          A dashboard you can drive from the keyboard        </a>      </li>      <li class="flex">        <a class="link link-quiet fg-text-strong" href="#">Why a deployment is immutable</a>      </li>    </ul>  </aside>  <footer class="shell-footer bt(1) bt-solid b-line-hair">    <div class="flex flex-wrap items-center justify-between gap-sm px(20) py-lg text-xs fg-text-muted">      <span>© 2026 Atlas Labs</span>      <nav class="flex flex-wrap gap-lg" aria-label="Footer">        <a class="link link-quiet" href="#">Privacy</a>        <a class="link link-quiet" href="#">Terms</a>        <a class="link link-quiet" href="#">RSS</a>      </nav>    </div>  </footer>  <dialog class="dialog dialog-drawer dialog-drawer-start" id="hg-nav" closedby="any" aria-label="Navigation">    <div class="dialog-body">      <nav class="nav" aria-label="Sections, in the drawer">        <a class="nav-item" href="#">Latest</a>        <a class="nav-item" href="#" aria-current="page">Engineering</a>        <a class="nav-item" href="#">Product</a>        <a class="nav-item" href="#">Company</a>        <a class="nav-item" href="#">Customers</a>      </nav>    </div>    <button type="button" class="btn btn-quiet btn-square btn-sm dialog-close" commandfor="hg-nav" command="close" aria-label="Close navigation">      <XIcon class="icon" />    </button>  </dialog></div>
<script setup>import MenuIcon from '@master/icons-vue/native/16/soft/menu'import ContrastIcon from '@master/icons-vue/native/16/soft/contrast'import XIcon from '@master/icons-vue/native/16/soft/x'</script><template>  <div class="shell bg-surface-base fg-text-body text-sm" style="--shell-sidebar: 13rem; --shell-aside: 15rem">    <header class="navbar shell-header bb(1) bb-solid b-line-hair" style="--navbar-padding-x: 1.25rem">      <button type="button" class="btn btn-quiet btn-square btn-sm shell-toggle" commandfor="hg-nav" command="show-modal" aria-label="Open navigation">        <MenuIcon class="icon" />      </button>      <a class="navbar-brand" href="#"><ContrastIcon class="icon" />Atlas</a>      <div class="navbar-end">        <button type="button" class="btn btn-primary btn-sm">Subscribe</button>      </div>    </header>    <main class="shell-main">      <article class="flex flex-col gap-md max-w(640) mx-auto px(20) py-xl">        <p class="eyebrow">Engineering</p>        <h1 class="heading heading-2xl">How we cut cold builds by forty seconds</h1>        <p class="lead">          Most of a cold build was spent fetching what the last build had already fetched. We stopped throwing it away.        </p>        <p class="m(0) leading-md">          A build starts from an empty machine. For years that was a feature: nothing left over from last time could break this time. It also meant every build downloaded the same two hundred megabytes of dependencies before doing any work of its own.        </p>        <p class="m(0) leading-md">          The fix was not a faster download. It was to key a cache by the lockfile, restore it before the install step, and let the package manager find that it had nothing to do. The install step now takes about three seconds when nothing changed, which is most of the time.        </p>        <p class="m(0) leading-md">          The main column is first in the source, before both side columns. The grid places each region by its class, so the order a screen reader meets them in is the order of importance, not the order on screen.        </p>        <p class="m(0) leading-md">          We measured for a month before turning it on for everyone. Median cold build time went from 96 seconds to 55, and the slowest tenth improved the most, because they had the most to download.        </p>      </article>    </main>    <div class="shell-sidebar p-sm bxe(1) bxe-solid b-line-hair">      <nav class="nav" aria-label="Sections">        <a class="nav-item" href="#">Latest</a>        <a class="nav-item" href="#" aria-current="page">Engineering</a>        <a class="nav-item" href="#">Product</a>        <a class="nav-item" href="#">Company</a>        <a class="nav-item" href="#">Customers</a>      </nav>    </div>    <aside class="shell-aside gap-md px-lg py-xl bxs(1) bxs-solid b-line-hair" aria-labelledby="hg-related">      <h2 class="eyebrow" id="hg-related">More from engineering</h2>      <ul class="flex flex-col gap-md m(0) p(0)">        <li class="flex">          <a class="link link-quiet fg-text-strong" href="#">            Preview comments, pinned to elements          </a>        </li>        <li class="flex">          <a class="link link-quiet fg-text-strong" href="#">            A dashboard you can drive from the keyboard          </a>        </li>        <li class="flex">          <a class="link link-quiet fg-text-strong" href="#">Why a deployment is immutable</a>        </li>      </ul>    </aside>    <footer class="shell-footer bt(1) bt-solid b-line-hair">      <div class="flex flex-wrap items-center justify-between gap-sm px(20) py-lg text-xs fg-text-muted">        <span>© 2026 Atlas Labs</span>        <nav class="flex flex-wrap gap-lg" aria-label="Footer">          <a class="link link-quiet" href="#">Privacy</a>          <a class="link link-quiet" href="#">Terms</a>          <a class="link link-quiet" href="#">RSS</a>        </nav>      </div>    </footer>    <dialog class="dialog dialog-drawer dialog-drawer-start" id="hg-nav" closedby="any" aria-label="Navigation">      <div class="dialog-body">        <nav class="nav" aria-label="Sections, in the drawer">          <a class="nav-item" href="#">Latest</a>          <a class="nav-item" href="#" aria-current="page">Engineering</a>          <a class="nav-item" href="#">Product</a>          <a class="nav-item" href="#">Company</a>          <a class="nav-item" href="#">Customers</a>        </nav>      </div>      <button type="button" class="btn btn-quiet btn-square btn-sm dialog-close" commandfor="hg-nav" command="close" aria-label="Close navigation">        <XIcon class="icon" />      </button>    </dialog>  </div></template>
向下滚动经过三栏后,页脚进入视口。平板预览中,末端侧边栏隐藏。手机预览中,起始侧边栏移入抽屉。

#布局结构

  • shell-header 和 shell-footer 横跨整个页面框架,shell-sidebar、shell-main 和 shell-aside 共用两者之间的一行。
  • 源码顺序可自行安排。 各区域在布局中的位置由各自的类决定,与标记中的顺序无关。这里将 <main> 紧接在页眉之后,排在两个侧边栏之前,因此屏幕阅读器、搜索引擎和 Tab 键导航都会先访问主要内容,再访问侧边栏。
  • 两侧边栏宽度固定,中栏宽度自适应。 用 --shell-sidebar 和 --shell-aside 设置侧边栏宽度,主要内容区域占据剩余空间,宽度始终以可用空间为上限。
  • 三栏所在行的高度至少等于视口高度,因此阅读过程中两侧边栏可以始终留在视口内,页脚则从首屏下方开始。
  • 整个框架共用一条边线。 页眉将 --navbar-padding-x 设为 1.25rem,即侧边栏内边距加上导航项内边距;页脚使用 px(20),因此品牌、章节和页脚文字都从同一条线开始。
  • 细线由工具类绘制。 bxe(1) bxe-solid b-line-hair 在起始侧边栏的末端画一条线,bxs(…) 在末端侧边栏的起始端画一条线,两条线的位置都随书写方向变化。

#何时使用

当同一份内容需要两个侧边栏分别提供导航入口和相关内容时,使用三栏布局。如果其中一栏只放本页目录,用文档布局就能更简洁地表达同样的结构。如果只有一个侧边栏,就是应用框架。

#无障碍

  • 起始侧边栏是包裹无障碍名称为“章节”的 <nav> 的普通元素,因此只构成一个地标,而不是两个。末端侧边栏内没有导航,它是以标题命名的 <aside>,其中的链接组成一个列表。
  • 将主要内容区域排在源码中三栏之首,正是为了让 Tab 键按页眉、主要内容、侧边栏的顺序移动焦点。检查这个顺序是否符合读者预期。如果不符合,将 <main> 移到导航之后。