網站導覽

v2.1.0
版面配置

可延伸欄

維持適合閱讀的欄寬,讓圖片或橫幅可以超出欄位,甚至延伸至兩側邊緣。

本頁內容

可延伸欄會在可用空間內置中,欄寬以舒適閱讀為準。圖片、表格或橫幅可以稍微超出文字欄,也可以延伸至兩側邊緣。長篇文章、變更紀錄或故事都適合這種版面配置,文字維持好讀的行長,其他內容則可使用更寬的空間。

子元素無須加上類別,預設就會排在閱讀欄中。需要向外延伸的項目才加上 breakout-wide 或 breakout-full。這個版面配置本身不繪製背景,滿版橫幅的外觀由工具類別或元件提供。

可延伸欄

<article class="breakout py-2xl bg-surface-base fg-text-body text-md leading-lg">  <header class="flex flex-col gap-xs">    <p class="eyebrow">Changelog · 12 November</p>    <h1 class="heading heading-2xl">Faster cold builds, and comments on previews</h1>    <p class="lead">      Dependency caches are now restored before the install step, and anyone with the link to a preview can leave a comment on it.    </p>  </header>  <p>    A cold build is one that starts with nothing: a new branch, a cleared cache, a project that has not built in a week. Until this release it downloaded every dependency again before it could restore anything, which made the first build of a branch the slowest one, and the one people waited for most.  </p>  <figure class="figure breakout-wide">    <img class="figure-media" src="/demo/harbor.svg" alt="A wooden jetty running out over calm water" style="--figure-ratio: 21 / 9">    <figcaption class="figure-caption">      The cache now waits at the end of the jetty, not the start: it is there before the install begins.    </figcaption>  </figure>  <h2 class="heading heading-lg mt-md">Caches before the install</h2>  <p>    The cache of a project is now keyed by its lockfile and restored before the install step runs. The install finds what it needs already in place and only fetches what changed. A branch that changes no dependency builds as fast as the one it came from.  </p>  <div class="breakout breakout-full py-xl bg-surface-tray">    <dl class="auto-grid" style="--auto-grid-min: 9rem">      <div class="stat">        <dt class="stat-label">Cold builds</dt>        <dd class="stat-row m(0)">          <span class="stat-value">38s</span><span class="stat-delta">21% faster</span>        </dd>      </div>      <div class="stat">        <dt class="stat-label">Installs skipped</dt>        <dd class="stat-row m(0)"><span class="stat-value">64%</span></dd>      </div>      <div class="stat">        <dt class="stat-label">Data fetched</dt>        <dd class="stat-row m(0)">          <span class="stat-value">1.9 GB</span><span class="stat-delta">48% less</span>        </dd>      </div>    </dl>  </div>  <h2 class="heading heading-lg mt-md">Comments on previews</h2>  <p>    Anyone with the link to a preview can now leave a comment on it, pinned to the place they mean. Comments are kept with the deploy, so they are still there when someone opens the same preview next week, and they are listed on the pull request.  </p>  <div class="scroll-area scroll-area-inline breakout-wide" tabindex="0" role="region" aria-label="Who can comment, by plan">    <table class="table">      <thead>        <tr class="table-row">          <th class="table-heading" scope="col">Plan</th>          <th class="table-heading" scope="col">Who can comment</th>          <th class="table-heading" scope="col">Kept for</th>          <th class="table-heading table-numeric" scope="col">Previews</th>        </tr>      </thead>      <tbody>        <tr class="table-row">          <th class="table-cell table-primary" scope="row">Free</th>          <td class="table-cell">Members of the team</td>          <td class="table-cell">30 days</td>          <td class="table-cell table-numeric">10</td>        </tr>        <tr class="table-row">          <th class="table-cell table-primary" scope="row">Pro</th>          <td class="table-cell">Anyone with the link</td>          <td class="table-cell">One year</td>          <td class="table-cell table-numeric">Unlimited</td>        </tr>      </tbody>    </table>  </div>  <p>Both changes are on for every project today. There is nothing to turn on.</p></article>
<article className="breakout py-2xl bg-surface-base fg-text-body text-md leading-lg">  <header className="flex flex-col gap-xs">    <p className="eyebrow">Changelog · 12 November</p>    <h1 className="heading heading-2xl">Faster cold builds, and comments on previews</h1>    <p className="lead">      Dependency caches are now restored before the install step, and anyone with the link to a preview can leave a comment on it.    </p>  </header>  <p>    A cold build is one that starts with nothing: a new branch, a cleared cache, a project that has not built in a week. Until this release it downloaded every dependency again before it could restore anything, which made the first build of a branch the slowest one, and the one people waited for most.  </p>  <figure className="figure breakout-wide">    <img className="figure-media" src="/demo/harbor.svg" alt="A wooden jetty running out over calm water" style={{ '--figure-ratio': '21 / 9' } as React.CSSProperties} />    <figcaption className="figure-caption">      The cache now waits at the end of the jetty, not the start: it is there before the install begins.    </figcaption>  </figure>  <h2 className="heading heading-lg mt-md">Caches before the install</h2>  <p>    The cache of a project is now keyed by its lockfile and restored before the install step runs. The install finds what it needs already in place and only fetches what changed. A branch that changes no dependency builds as fast as the one it came from.  </p>  <div className="breakout breakout-full py-xl bg-surface-tray">    <dl className="auto-grid" style={{ '--auto-grid-min': '9rem' } as React.CSSProperties}>      <div className="stat">        <dt className="stat-label">Cold builds</dt>        <dd className="stat-row m(0)">          <span className="stat-value">38s</span><span className="stat-delta">21% faster</span>        </dd>      </div>      <div className="stat">        <dt className="stat-label">Installs skipped</dt>        <dd className="stat-row m(0)"><span className="stat-value">64%</span></dd>      </div>      <div className="stat">        <dt className="stat-label">Data fetched</dt>        <dd className="stat-row m(0)">          <span className="stat-value">1.9 GB</span><span className="stat-delta">48% less</span>        </dd>      </div>    </dl>  </div>  <h2 className="heading heading-lg mt-md">Comments on previews</h2>  <p>    Anyone with the link to a preview can now leave a comment on it, pinned to the place they mean. Comments are kept with the deploy, so they are still there when someone opens the same preview next week, and they are listed on the pull request.  </p>  <div className="scroll-area scroll-area-inline breakout-wide" tabIndex={0} role="region" aria-label="Who can comment, by plan">    <table className="table">      <thead>        <tr className="table-row">          <th className="table-heading" scope="col">Plan</th>          <th className="table-heading" scope="col">Who can comment</th>          <th className="table-heading" scope="col">Kept for</th>          <th className="table-heading table-numeric" scope="col">Previews</th>        </tr>      </thead>      <tbody>        <tr className="table-row">          <th className="table-cell table-primary" scope="row">Free</th>          <td className="table-cell">Members of the team</td>          <td className="table-cell">30 days</td>          <td className="table-cell table-numeric">10</td>        </tr>        <tr className="table-row">          <th className="table-cell table-primary" scope="row">Pro</th>          <td className="table-cell">Anyone with the link</td>          <td className="table-cell">One year</td>          <td className="table-cell table-numeric">Unlimited</td>        </tr>      </tbody>    </table>  </div>  <p>Both changes are on for every project today. There is nothing to turn on.</p></article>
<article class="breakout py-2xl bg-surface-base fg-text-body text-md leading-lg">  <header class="flex flex-col gap-xs">    <p class="eyebrow">Changelog · 12 November</p>    <h1 class="heading heading-2xl">Faster cold builds, and comments on previews</h1>    <p class="lead">      Dependency caches are now restored before the install step, and anyone with the link to a preview can leave a comment on it.    </p>  </header>  <p>    A cold build is one that starts with nothing: a new branch, a cleared cache, a project that has not built in a week. Until this release it downloaded every dependency again before it could restore anything, which made the first build of a branch the slowest one, and the one people waited for most.  </p>  <figure class="figure breakout-wide">    <img class="figure-media" src="/demo/harbor.svg" alt="A wooden jetty running out over calm water" style="--figure-ratio: 21 / 9">    <figcaption class="figure-caption">      The cache now waits at the end of the jetty, not the start: it is there before the install begins.    </figcaption>  </figure>  <h2 class="heading heading-lg mt-md">Caches before the install</h2>  <p>    The cache of a project is now keyed by its lockfile and restored before the install step runs. The install finds what it needs already in place and only fetches what changed. A branch that changes no dependency builds as fast as the one it came from.  </p>  <div class="breakout breakout-full py-xl bg-surface-tray">    <dl class="auto-grid" style="--auto-grid-min: 9rem">      <div class="stat">        <dt class="stat-label">Cold builds</dt>        <dd class="stat-row m(0)">          <span class="stat-value">38s</span><span class="stat-delta">21% faster</span>        </dd>      </div>      <div class="stat">        <dt class="stat-label">Installs skipped</dt>        <dd class="stat-row m(0)"><span class="stat-value">64%</span></dd>      </div>      <div class="stat">        <dt class="stat-label">Data fetched</dt>        <dd class="stat-row m(0)">          <span class="stat-value">1.9 GB</span><span class="stat-delta">48% less</span>        </dd>      </div>    </dl>  </div>  <h2 class="heading heading-lg mt-md">Comments on previews</h2>  <p>    Anyone with the link to a preview can now leave a comment on it, pinned to the place they mean. Comments are kept with the deploy, so they are still there when someone opens the same preview next week, and they are listed on the pull request.  </p>  <div class="scroll-area scroll-area-inline breakout-wide" tabindex="0" role="region" aria-label="Who can comment, by plan">    <table class="table">      <thead>        <tr class="table-row">          <th class="table-heading" scope="col">Plan</th>          <th class="table-heading" scope="col">Who can comment</th>          <th class="table-heading" scope="col">Kept for</th>          <th class="table-heading table-numeric" scope="col">Previews</th>        </tr>      </thead>      <tbody>        <tr class="table-row">          <th class="table-cell table-primary" scope="row">Free</th>          <td class="table-cell">Members of the team</td>          <td class="table-cell">30 days</td>          <td class="table-cell table-numeric">10</td>        </tr>        <tr class="table-row">          <th class="table-cell table-primary" scope="row">Pro</th>          <td class="table-cell">Anyone with the link</td>          <td class="table-cell">One year</td>          <td class="table-cell table-numeric">Unlimited</td>        </tr>      </tbody>    </table>  </div>  <p>Both changes are on for every project today. There is nothing to turn on.</p></article>
<template>  <article class="breakout py-2xl bg-surface-base fg-text-body text-md leading-lg">    <header class="flex flex-col gap-xs">      <p class="eyebrow">Changelog · 12 November</p>      <h1 class="heading heading-2xl">Faster cold builds, and comments on previews</h1>      <p class="lead">        Dependency caches are now restored before the install step, and anyone with the link to a preview can leave a comment on it.      </p>    </header>    <p>      A cold build is one that starts with nothing: a new branch, a cleared cache, a project that has not built in a week. Until this release it downloaded every dependency again before it could restore anything, which made the first build of a branch the slowest one, and the one people waited for most.    </p>    <figure class="figure breakout-wide">      <img class="figure-media" src="/demo/harbor.svg" alt="A wooden jetty running out over calm water" style="--figure-ratio: 21 / 9">      <figcaption class="figure-caption">        The cache now waits at the end of the jetty, not the start: it is there before the install begins.      </figcaption>    </figure>    <h2 class="heading heading-lg mt-md">Caches before the install</h2>    <p>      The cache of a project is now keyed by its lockfile and restored before the install step runs. The install finds what it needs already in place and only fetches what changed. A branch that changes no dependency builds as fast as the one it came from.    </p>    <div class="breakout breakout-full py-xl bg-surface-tray">      <dl class="auto-grid" style="--auto-grid-min: 9rem">        <div class="stat">          <dt class="stat-label">Cold builds</dt>          <dd class="stat-row m(0)">            <span class="stat-value">38s</span><span class="stat-delta">21% faster</span>          </dd>        </div>        <div class="stat">          <dt class="stat-label">Installs skipped</dt>          <dd class="stat-row m(0)"><span class="stat-value">64%</span></dd>        </div>        <div class="stat">          <dt class="stat-label">Data fetched</dt>          <dd class="stat-row m(0)">            <span class="stat-value">1.9 GB</span><span class="stat-delta">48% less</span>          </dd>        </div>      </dl>    </div>    <h2 class="heading heading-lg mt-md">Comments on previews</h2>    <p>      Anyone with the link to a preview can now leave a comment on it, pinned to the place they mean. Comments are kept with the deploy, so they are still there when someone opens the same preview next week, and they are listed on the pull request.    </p>    <div class="scroll-area scroll-area-inline breakout-wide" tabindex="0" role="region" aria-label="Who can comment, by plan">      <table class="table">        <thead>          <tr class="table-row">            <th class="table-heading" scope="col">Plan</th>            <th class="table-heading" scope="col">Who can comment</th>            <th class="table-heading" scope="col">Kept for</th>            <th class="table-heading table-numeric" scope="col">Previews</th>          </tr>        </thead>        <tbody>          <tr class="table-row">            <th class="table-cell table-primary" scope="row">Free</th>            <td class="table-cell">Members of the team</td>            <td class="table-cell">30 days</td>            <td class="table-cell table-numeric">10</td>          </tr>          <tr class="table-row">            <th class="table-cell table-primary" scope="row">Pro</th>            <td class="table-cell">Anyone with the link</td>            <td class="table-cell">One year</td>            <td class="table-cell table-numeric">Unlimited</td>          </tr>        </tbody>      </table>    </div>    <p>Both changes are on for every project today. There is nothing to turn on.</p>  </article></template>
捲動閱讀文章,再切換到平板和手機。文字維持適合閱讀的欄寬,圖片和表格依欄位兩側的可用空間調整寬度,橫幅則始終延伸至兩側邊緣。

#版面配置原理

  • 單一欄軌。 可延伸欄是只有一欄的格線。欄寬取 --breakout-measure(預設為 40rem)與可用寬度扣除兩側各一個 --breakout-gutter 後的寬度,兩者取較小值。閱讀欄置中,子元素無須加上類別就會排進欄內。
  • 以外距向欄外延伸。 可延伸欄是行內尺寸容器。對子元素而言,100cqi 是容器寬度,100% 是欄寬,因此欄位任一側的可用空間就是兩者差值的一半。breakout-wide 以負外距向兩側延伸,每側最多 --breakout-wide,並保留邊距。breakout-full 則延伸至容器邊緣。
  • 滿版橫幅內的文字與正文對齊。 滿版子元素也可以套用 breakout,讓橫幅延伸至兩側邊緣,同時把自己的子元素排在同樣欄寬的欄位裡。上方範例中,橫幅裡的數字與橫幅前後的正文對齊。
  • 用列間距統一垂直間隔。 格線中的外距不會合併,因此子元素以 1.25rem 的列間距隔開。標題加上 mt-md,讓標題與上方內容的間距略大於與下方內容的間距。
  • 寬表格可獨立捲動。 將表格放在加上 scroll-area-inline 和 breakout-wide 的捲動區域內。這樣在手機上就能於欄內橫向捲動表格,避免撐寬頁面。

#加寬與滿版

子元素能延伸多遠,取決於欄位兩側還有多少空間,也就是頁面的寬度。

可用寬度閱讀欄breakout-widebreakout-full
大於欄寬上限加上兩側的最大延伸量40rem,置中每側多 8rem,共 56rem整個可用寬度
介於上述與下述兩種情況之間40rem,置中可用寬度扣除兩側邊距整個可用寬度
小於欄寬上限可用寬度扣除兩側邊距與閱讀欄同寬整個可用寬度

寬度

<div class="breakout py-lg fg-text-muted text-sm" style="--breakout-measure: 20rem; --breakout-wide: 5rem">  <div class="well flex items-center justify-center h(56)">The column</div>  <div class="well flex items-center justify-center h(56) breakout-wide">breakout-wide</div>  <div class="well flex items-center justify-center h(56) breakout-full">breakout-full</div>  <div class="well flex items-center justify-center h(56)">The column</div></div>
<div className="breakout py-lg fg-text-muted text-sm" style={{ '--breakout-measure': '20rem', '--breakout-wide': '5rem' } as React.CSSProperties}>  <div className="well flex items-center justify-center h(56)">The column</div>  <div className="well flex items-center justify-center h(56) breakout-wide">breakout-wide</div>  <div className="well flex items-center justify-center h(56) breakout-full">breakout-full</div>  <div className="well flex items-center justify-center h(56)">The column</div></div>
<div class="breakout py-lg fg-text-muted text-sm" style="--breakout-measure: 20rem; --breakout-wide: 5rem">  <div class="well flex items-center justify-center h(56)">The column</div>  <div class="well flex items-center justify-center h(56) breakout-wide">breakout-wide</div>  <div class="well flex items-center justify-center h(56) breakout-full">breakout-full</div>  <div class="well flex items-center justify-center h(56)">The column</div></div>
<template>  <div class="breakout py-lg fg-text-muted text-sm" style="--breakout-measure: 20rem; --breakout-wide: 5rem">    <div class="well flex items-center justify-center h(56)">The column</div>    <div class="well flex items-center justify-center h(56) breakout-wide">breakout-wide</div>    <div class="well flex items-center justify-center h(56) breakout-full">breakout-full</div>    <div class="well flex items-center justify-center h(56)">The column</div>  </div></template>

--breakout-measure 設定閱讀欄的最大寬度。欄寬為 40rem 時,每行約可容納 70 個正文文字字元。字級較大時可調低這個值,程式碼欄則可調高。--breakout-wide 設定加寬項目在每側最多可延伸多遠,--breakout-gutter 則設定非滿版項目與容器邊緣之間至少要保留多少空間。

#滿版橫幅

滿版橫幅通常以色塊或圖片為底,上面的文字仍應對齊閱讀欄。將橫幅本身也設為可延伸欄。它作為 breakout-full 子元素延伸至兩側邊緣,裡面的子元素則排在與前後正文同寬的欄位內。

<div class="breakout breakout-full py-xl bg-surface-tray">  <p>These words line up with the column above and below the band.</p></div>

可延伸欄本身不繪製背景,因此橫幅的底色由工具類別 bg-surface-tray 提供。若要讓圖片延伸至兩側邊緣,請在圖文上使用 breakout-full 並設定 --figure-radius: 0,讓圖片的直角貼齊視窗邊緣。

#使用時機

文章、部落格文章、變更紀錄或指南等以單欄閱讀為主的頁面,適合使用可延伸欄。它放在頁面的主要區域中。如果閱讀欄旁還有導覽、目錄等區域,請使用文件頁面,其中的文章欄仍可設為可延伸欄。若所有內容都留在欄內,直接使用工具類別 max-w(640) mx-auto 並加上兩側邊距即可。

#無障礙

  • 可延伸欄只調整寬度,閱讀順序仍依標記中的排列。
  • 欄寬以 rem 設定,因此會隨讀者的文字大小調整。字級放大時,欄位也會加寬,每行仍約可容納 70 個字元。當視窗容不下這個寬度時,欄位會隨視窗縮窄,避免頁面出現橫向捲動。
  • 表格超出欄寬時,請將它放在有名稱並設有 tabindex="0" 的捲動區域中,讓使用者也能以鍵盤捲動。

#類別

類別說明
breakout格線只有一欄,置中且寬度最多為 --breakout-measure,與兩側邊緣各至少相距 --breakout-gutter。子元素間距為 1.25rem。這是 inline-size 查詢容器,本身不繪製任何內容
breakout-wide子元素可從閱讀欄向左右各延伸最多 --breakout-wide,實際延伸量取決於兩側可用空間,且須保留距容器邊緣的最小間距
breakout-full延伸至 breakout 左右邊緣的子元素

#自訂屬性

屬性預設值說明
--breakout-measure40rem欄位的最大寬度,約可容納 70 個正文字元
--breakout-wide8rem較寬的子元素可向欄位左右各延伸的距離
--breakout-gutter1.5rem欄與邊緣之間,以及較寬的子元素與邊緣之間保留的最小間距

#原始碼

@master/ui/layouts/breakout.css
/* * Breakout: a column at a reading measure, centred in the room it is given, that a figure, a table or a band * can step out of: wider by up to --breakout-wide on each side, or to the edges of the room. It draws no surface; * a band that runs to the edges takes its face from a component or a utility. * * Everything inside reads in the column without a class. The column is the grid's one track, at most * --breakout-measure and never closer than --breakout-gutter to an edge, so every child lands in it by itself. * A child that leaves it does so with negative margins measured against the breakout's own width: the breakout * is an inline-size container, so 100cqi in a child is the room and 100% is the column. A wide child takes what * room there is beside the column, up to --breakout-wide and never into the gutter; on a phone, where there is * none, it is as wide as the column. A full child runs to both edges. * * Children are 1.25rem apart, the rhythm of running text; change it with a gap utility on the breakout. */@layer components.ui {  .breakout {    --breakout-measure: 40rem;    --breakout-wide: 8rem;    --breakout-gutter: 1.5rem;    display: grid;    grid-template-columns: minmax(0, min(var(--breakout-measure), 100% - var(--breakout-gutter) * 2));    justify-content: center;    align-content: start;    row-gap: 1.25rem;    min-width: 0;    container-type: inline-size;  }  .breakout-wide {    margin-inline: calc(-1 * min(var(--breakout-wide), (100cqi - 100%) / 2 - var(--breakout-gutter)));  }  .breakout-full {    margin-inline: calc((100% - 100cqi) / 2);  }}