导航

v2.1.0
布局

Bento 布局

把不同尺寸的区块排在同一个网格中,列数随网格自身的可用宽度调整。

本页内容

Bento 布局把几个大小不同的区块排在同一个容器里,适合展示产品功能或个人资料亮点:一块大的,旁边一块高的,周围再排几块小的。布局只负责排列,本身不绘制表面。区块由卡片、面板及其承载的内容组成。

列数和区块的跨度都取决于布局自身的可用宽度,与视口宽度无关。达到 48rem 时为四列,达到 28rem 但不足 48rem 时为两列,低于 28rem 时为一列。在四列布局中跨两列的区块,在两列时占满整行,在一列时占一个单元格。因此,同一套标记在桌面端错落排列,在手机上排成一列。

Bento 布局

<section class="flex flex-col gap-xl p-xl bg-surface-base fg-text-body text-sm" aria-labelledby="bento-title">  <header class="flex flex-col gap-xs max-w(560)">    <p class="eyebrow">Platform</p>    <h2 class="heading heading-xl" id="bento-title">Everything a deploy needs</h2>  </header>  <div class="bento">    <article class="card card-split bento-large">      <img class="card-media" src="/demo/moonstone.svg" alt>      <header class="card-header">        <h3 class="card-title">Live at the edge</h3>        <p class="card-description">          Every push is served from 14 regions before the review is done.        </p>      </header>      <p class="card-body">        Static files, functions and images are cached where the reader is, and purged the moment a deploy replaces them.      </p>      <footer class="card-footer"><a class="btn btn-sm" href="#regions">See the regions</a></footer>    </article>    <article class="card bento-tall">      <header class="card-header">        <h3 class="card-title">Reviewed together</h3>        <p class="card-description">Comments land on the preview, beside what they are about.</p>      </header>      <div class="card-body flex flex-col gap-sm">        <div class="avatar-group" role="group" aria-label="Ada Lovelace, Alan Turing, Grace Hopper and 5 others">          <span class="avatar avatar-sm">            <img class="avatar-image" src="/demo/portrait-1.svg" alt>          </span>          <span class="avatar avatar-sm">            <img class="avatar-image" src="/demo/portrait-2.svg" alt>          </span>          <span class="avatar avatar-sm">            <img class="avatar-image" src="/demo/portrait-3.svg" alt>          </span>          <span class="avatar avatar-sm" aria-hidden="true">+5</span>        </div>        <p class="m(0)">          Eight people left 23 comments on this week's previews. Four are still open.        </p>      </div>      <footer class="card-footer"><a class="btn btn-sm" href="#comments">Open comments</a></footer>    </article>    <article class="card">      <div class="stat">        <p class="stat-label">Cold builds</p>        <div class="stat-row">          <p class="stat-value">38s</p>          <p class="stat-delta">21% faster</p>        </div>        <p class="stat-description">Caches are restored before the install.</p>      </div>    </article>    <article class="card">      <header class="card-header">        <h3 class="card-title">Rollbacks</h3>        <p class="card-description">Any deploy is one click away, and so is the one before it.</p>      </header>    </article>    <article class="card bento-wide">      <header class="card-header">        <h3 class="card-title">Builds this week</h3>        <p class="card-description">Thursday so far</p>      </header>      <figure class="chart chart-quiet" style="--chart-height: 4.5rem">        <div class="chart-body">          <svg class="chart-plot" role="list" aria-label="Builds per day, this week">            <g aria-hidden="true">              <line class="chart-grid chart-grid-base" x1="0" y1="100%" x2="100%" y2="100%" />              <line class="chart-grid" x1="0" y1="75%" x2="100%" y2="75%" />              <line class="chart-grid" x1="0" y1="50%" x2="100%" y2="50%" />              <line class="chart-grid" x1="0" y1="25%" x2="100%" y2="25%" />              <line class="chart-grid" x1="0" y1="0%" x2="100%" y2="0%" />              <text class="chart-tick chart-tick-x" x="7.143%" y="100%">Mon</text>              <text class="chart-tick chart-tick-x" x="21.429%" y="100%">Tue</text>              <text class="chart-tick chart-tick-x" x="35.714%" y="100%">Wed</text>              <text class="chart-tick chart-tick-x" x="50%" y="100%">Thu</text>              <text class="chart-tick chart-tick-x" x="64.286%" y="100%">Fri</text>              <text class="chart-tick chart-tick-x" x="78.571%" y="100%">Sat</text>              <text class="chart-tick chart-tick-x" x="92.857%" y="100%">Sun</text>            </g>            <g class="chart-point" role="listitem" aria-label="Mon: 42">              <rect class="chart-hit" x="0%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="2.714%" y="47.5%" width="8.857%" height="52.5%" />            </g>            <g class="chart-point" role="listitem" aria-label="Tue: 58">              <rect class="chart-hit" x="14.286%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="17%" y="27.5%" width="8.857%" height="72.5%" />            </g>            <g class="chart-point" role="listitem" aria-label="Wed: 36">              <rect class="chart-hit" x="28.571%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="31.286%" y="55%" width="8.857%" height="45%" />            </g>            <g class="chart-point" role="listitem" aria-label="Thu: 71" aria-current="true">              <rect class="chart-hit" x="42.857%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="45.571%" y="11.25%" width="8.857%" height="88.75%" />            </g>            <g class="chart-point" role="listitem" aria-label="Fri: 0">              <rect class="chart-hit" x="57.143%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="59.857%" y="99.4%" width="8.857%" height="0.6%" />            </g>            <g class="chart-point" role="listitem" aria-label="Sat: 0">              <rect class="chart-hit" x="71.429%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="74.143%" y="99.4%" width="8.857%" height="0.6%" />            </g>            <g class="chart-point" role="listitem" aria-label="Sun: 0">              <rect class="chart-hit" x="85.714%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="88.429%" y="99.4%" width="8.857%" height="0.6%" />            </g>          </svg>        </div>      </figure>    </article>    <article class="sheet sheet-inverse bento-wide flex flex-col justify-between gap-md p(20)">      <div class="flex flex-col gap-3xs">        <h3 class="heading heading-sm fg-text-inverse">Start on the free plan</h3>        <p class="m(0)">Three projects and every feature above. No card needed.</p>      </div>      <div class="flex"><a class="btn btn-sm" href="#start">Create a project</a></div>    </article>  </div></section>
<section className="flex flex-col gap-xl p-xl bg-surface-base fg-text-body text-sm" aria-labelledby="bento-title">  <header className="flex flex-col gap-xs max-w(560)">    <p className="eyebrow">Platform</p>    <h2 className="heading heading-xl" id="bento-title">Everything a deploy needs</h2>  </header>  <div className="bento">    <article className="card card-split bento-large">      <img className="card-media" src="/demo/moonstone.svg" alt="" />      <header className="card-header">        <h3 className="card-title">Live at the edge</h3>        <p className="card-description">          Every push is served from 14 regions before the review is done.        </p>      </header>      <p className="card-body">        Static files, functions and images are cached where the reader is, and purged the moment a deploy replaces them.      </p>      <footer className="card-footer">        <a className="btn btn-sm" href="#regions">See the regions</a>      </footer>    </article>    <article className="card bento-tall">      <header className="card-header">        <h3 className="card-title">Reviewed together</h3>        <p className="card-description">          Comments land on the preview, beside what they are about.        </p>      </header>      <div className="card-body flex flex-col gap-sm">        <div className="avatar-group" role="group" aria-label="Ada Lovelace, Alan Turing, Grace Hopper and 5 others">          <span className="avatar avatar-sm">            <img className="avatar-image" src="/demo/portrait-1.svg" alt="" />          </span>          <span className="avatar avatar-sm">            <img className="avatar-image" src="/demo/portrait-2.svg" alt="" />          </span>          <span className="avatar avatar-sm">            <img className="avatar-image" src="/demo/portrait-3.svg" alt="" />          </span>          <span className="avatar avatar-sm" aria-hidden="true">+5</span>        </div>        <p className="m(0)">          Eight people left 23 comments on this week's previews. Four are still open.        </p>      </div>      <footer className="card-footer">        <a className="btn btn-sm" href="#comments">Open comments</a>      </footer>    </article>    <article className="card">      <div className="stat">        <p className="stat-label">Cold builds</p>        <div className="stat-row">          <p className="stat-value">38s</p>          <p className="stat-delta">21% faster</p>        </div>        <p className="stat-description">Caches are restored before the install.</p>      </div>    </article>    <article className="card">      <header className="card-header">        <h3 className="card-title">Rollbacks</h3>        <p className="card-description">          Any deploy is one click away, and so is the one before it.        </p>      </header>    </article>    <article className="card bento-wide">      <header className="card-header">        <h3 className="card-title">Builds this week</h3>        <p className="card-description">Thursday so far</p>      </header>      <figure className="chart chart-quiet" style={{ '--chart-height': '4.5rem' } as React.CSSProperties}>        <div className="chart-body">          <svg className="chart-plot" role="list" aria-label="Builds per day, this week">            <g aria-hidden="true">              <line className="chart-grid chart-grid-base" x1="0" y1="100%" x2="100%" y2="100%" />              <line className="chart-grid" x1="0" y1="75%" x2="100%" y2="75%" />              <line className="chart-grid" x1="0" y1="50%" x2="100%" y2="50%" />              <line className="chart-grid" x1="0" y1="25%" x2="100%" y2="25%" />              <line className="chart-grid" x1="0" y1="0%" x2="100%" y2="0%" />              <text className="chart-tick chart-tick-x" x="7.143%" y="100%">Mon</text>              <text className="chart-tick chart-tick-x" x="21.429%" y="100%">Tue</text>              <text className="chart-tick chart-tick-x" x="35.714%" y="100%">Wed</text>              <text className="chart-tick chart-tick-x" x="50%" y="100%">Thu</text>              <text className="chart-tick chart-tick-x" x="64.286%" y="100%">Fri</text>              <text className="chart-tick chart-tick-x" x="78.571%" y="100%">Sat</text>              <text className="chart-tick chart-tick-x" x="92.857%" y="100%">Sun</text>            </g>            <g className="chart-point" role="listitem" aria-label="Mon: 42">              <rect className="chart-hit" x="0%" y="0" width="14.286%" height="100%" />              <rect className="chart-bar" x="2.714%" y="47.5%" width="8.857%" height="52.5%" />            </g>            <g className="chart-point" role="listitem" aria-label="Tue: 58">              <rect className="chart-hit" x="14.286%" y="0" width="14.286%" height="100%" />              <rect className="chart-bar" x="17%" y="27.5%" width="8.857%" height="72.5%" />            </g>            <g className="chart-point" role="listitem" aria-label="Wed: 36">              <rect className="chart-hit" x="28.571%" y="0" width="14.286%" height="100%" />              <rect className="chart-bar" x="31.286%" y="55%" width="8.857%" height="45%" />            </g>            <g className="chart-point" role="listitem" aria-label="Thu: 71" aria-current="true">              <rect className="chart-hit" x="42.857%" y="0" width="14.286%" height="100%" />              <rect className="chart-bar" x="45.571%" y="11.25%" width="8.857%" height="88.75%" />            </g>            <g className="chart-point" role="listitem" aria-label="Fri: 0">              <rect className="chart-hit" x="57.143%" y="0" width="14.286%" height="100%" />              <rect className="chart-bar" x="59.857%" y="99.4%" width="8.857%" height="0.6%" />            </g>            <g className="chart-point" role="listitem" aria-label="Sat: 0">              <rect className="chart-hit" x="71.429%" y="0" width="14.286%" height="100%" />              <rect className="chart-bar" x="74.143%" y="99.4%" width="8.857%" height="0.6%" />            </g>            <g className="chart-point" role="listitem" aria-label="Sun: 0">              <rect className="chart-hit" x="85.714%" y="0" width="14.286%" height="100%" />              <rect className="chart-bar" x="88.429%" y="99.4%" width="8.857%" height="0.6%" />            </g>          </svg>        </div>      </figure>    </article>    <article className="sheet sheet-inverse bento-wide flex flex-col justify-between gap-md p(20)">      <div className="flex flex-col gap-3xs">        <h3 className="heading heading-sm fg-text-inverse">Start on the free plan</h3>        <p className="m(0)">Three projects and every feature above. No card needed.</p>      </div>      <div className="flex"><a className="btn btn-sm" href="#start">Create a project</a></div>    </article>  </div></section>
<section class="flex flex-col gap-xl p-xl bg-surface-base fg-text-body text-sm" aria-labelledby="bento-title">  <header class="flex flex-col gap-xs max-w(560)">    <p class="eyebrow">Platform</p>    <h2 class="heading heading-xl" id="bento-title">Everything a deploy needs</h2>  </header>  <div class="bento">    <article class="card card-split bento-large">      <img class="card-media" src="/demo/moonstone.svg" alt>      <header class="card-header">        <h3 class="card-title">Live at the edge</h3>        <p class="card-description">          Every push is served from 14 regions before the review is done.        </p>      </header>      <p class="card-body">        Static files, functions and images are cached where the reader is, and purged the moment a deploy replaces them.      </p>      <footer class="card-footer"><a class="btn btn-sm" href="#regions">See the regions</a></footer>    </article>    <article class="card bento-tall">      <header class="card-header">        <h3 class="card-title">Reviewed together</h3>        <p class="card-description">Comments land on the preview, beside what they are about.</p>      </header>      <div class="card-body flex flex-col gap-sm">        <div class="avatar-group" role="group" aria-label="Ada Lovelace, Alan Turing, Grace Hopper and 5 others">          <span class="avatar avatar-sm">            <img class="avatar-image" src="/demo/portrait-1.svg" alt>          </span>          <span class="avatar avatar-sm">            <img class="avatar-image" src="/demo/portrait-2.svg" alt>          </span>          <span class="avatar avatar-sm">            <img class="avatar-image" src="/demo/portrait-3.svg" alt>          </span>          <span class="avatar avatar-sm" aria-hidden="true">+5</span>        </div>        <p class="m(0)">          Eight people left 23 comments on this week's previews. Four are still open.        </p>      </div>      <footer class="card-footer"><a class="btn btn-sm" href="#comments">Open comments</a></footer>    </article>    <article class="card">      <div class="stat">        <p class="stat-label">Cold builds</p>        <div class="stat-row">          <p class="stat-value">38s</p>          <p class="stat-delta">21% faster</p>        </div>        <p class="stat-description">Caches are restored before the install.</p>      </div>    </article>    <article class="card">      <header class="card-header">        <h3 class="card-title">Rollbacks</h3>        <p class="card-description">Any deploy is one click away, and so is the one before it.</p>      </header>    </article>    <article class="card bento-wide">      <header class="card-header">        <h3 class="card-title">Builds this week</h3>        <p class="card-description">Thursday so far</p>      </header>      <figure class="chart chart-quiet" style="--chart-height: 4.5rem">        <div class="chart-body">          <svg class="chart-plot" role="list" aria-label="Builds per day, this week">            <g aria-hidden="true">              <line class="chart-grid chart-grid-base" x1="0" y1="100%" x2="100%" y2="100%" />              <line class="chart-grid" x1="0" y1="75%" x2="100%" y2="75%" />              <line class="chart-grid" x1="0" y1="50%" x2="100%" y2="50%" />              <line class="chart-grid" x1="0" y1="25%" x2="100%" y2="25%" />              <line class="chart-grid" x1="0" y1="0%" x2="100%" y2="0%" />              <text class="chart-tick chart-tick-x" x="7.143%" y="100%">Mon</text>              <text class="chart-tick chart-tick-x" x="21.429%" y="100%">Tue</text>              <text class="chart-tick chart-tick-x" x="35.714%" y="100%">Wed</text>              <text class="chart-tick chart-tick-x" x="50%" y="100%">Thu</text>              <text class="chart-tick chart-tick-x" x="64.286%" y="100%">Fri</text>              <text class="chart-tick chart-tick-x" x="78.571%" y="100%">Sat</text>              <text class="chart-tick chart-tick-x" x="92.857%" y="100%">Sun</text>            </g>            <g class="chart-point" role="listitem" aria-label="Mon: 42">              <rect class="chart-hit" x="0%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="2.714%" y="47.5%" width="8.857%" height="52.5%" />            </g>            <g class="chart-point" role="listitem" aria-label="Tue: 58">              <rect class="chart-hit" x="14.286%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="17%" y="27.5%" width="8.857%" height="72.5%" />            </g>            <g class="chart-point" role="listitem" aria-label="Wed: 36">              <rect class="chart-hit" x="28.571%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="31.286%" y="55%" width="8.857%" height="45%" />            </g>            <g class="chart-point" role="listitem" aria-label="Thu: 71" aria-current="true">              <rect class="chart-hit" x="42.857%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="45.571%" y="11.25%" width="8.857%" height="88.75%" />            </g>            <g class="chart-point" role="listitem" aria-label="Fri: 0">              <rect class="chart-hit" x="57.143%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="59.857%" y="99.4%" width="8.857%" height="0.6%" />            </g>            <g class="chart-point" role="listitem" aria-label="Sat: 0">              <rect class="chart-hit" x="71.429%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="74.143%" y="99.4%" width="8.857%" height="0.6%" />            </g>            <g class="chart-point" role="listitem" aria-label="Sun: 0">              <rect class="chart-hit" x="85.714%" y="0" width="14.286%" height="100%" />              <rect class="chart-bar" x="88.429%" y="99.4%" width="8.857%" height="0.6%" />            </g>          </svg>        </div>      </figure>    </article>    <article class="sheet sheet-inverse bento-wide flex flex-col justify-between gap-md p(20)">      <div class="flex flex-col gap-3xs">        <h3 class="heading heading-sm fg-text-inverse">Start on the free plan</h3>        <p class="m(0)">Three projects and every feature above. No card needed.</p>      </div>      <div class="flex"><a class="btn btn-sm" href="#start">Create a project</a></div>    </article>  </div></section>
<template>  <section class="flex flex-col gap-xl p-xl bg-surface-base fg-text-body text-sm" aria-labelledby="bento-title">    <header class="flex flex-col gap-xs max-w(560)">      <p class="eyebrow">Platform</p>      <h2 class="heading heading-xl" id="bento-title">Everything a deploy needs</h2>    </header>    <div class="bento">      <article class="card card-split bento-large">        <img class="card-media" src="/demo/moonstone.svg" alt>        <header class="card-header">          <h3 class="card-title">Live at the edge</h3>          <p class="card-description">            Every push is served from 14 regions before the review is done.          </p>        </header>        <p class="card-body">          Static files, functions and images are cached where the reader is, and purged the moment a deploy replaces them.        </p>        <footer class="card-footer">          <a class="btn btn-sm" href="#regions">See the regions</a>        </footer>      </article>      <article class="card bento-tall">        <header class="card-header">          <h3 class="card-title">Reviewed together</h3>          <p class="card-description">Comments land on the preview, beside what they are about.</p>        </header>        <div class="card-body flex flex-col gap-sm">          <div class="avatar-group" role="group" aria-label="Ada Lovelace, Alan Turing, Grace Hopper and 5 others">            <span class="avatar avatar-sm">              <img class="avatar-image" src="/demo/portrait-1.svg" alt>            </span>            <span class="avatar avatar-sm">              <img class="avatar-image" src="/demo/portrait-2.svg" alt>            </span>            <span class="avatar avatar-sm">              <img class="avatar-image" src="/demo/portrait-3.svg" alt>            </span>            <span class="avatar avatar-sm" aria-hidden="true">+5</span>          </div>          <p class="m(0)">            Eight people left 23 comments on this week's previews. Four are still open.          </p>        </div>        <footer class="card-footer">          <a class="btn btn-sm" href="#comments">Open comments</a>        </footer>      </article>      <article class="card">        <div class="stat">          <p class="stat-label">Cold builds</p>          <div class="stat-row">            <p class="stat-value">38s</p>            <p class="stat-delta">21% faster</p>          </div>          <p class="stat-description">Caches are restored before the install.</p>        </div>      </article>      <article class="card">        <header class="card-header">          <h3 class="card-title">Rollbacks</h3>          <p class="card-description">Any deploy is one click away, and so is the one before it.</p>        </header>      </article>      <article class="card bento-wide">        <header class="card-header">          <h3 class="card-title">Builds this week</h3>          <p class="card-description">Thursday so far</p>        </header>        <figure class="chart chart-quiet" style="--chart-height: 4.5rem">          <div class="chart-body">            <svg class="chart-plot" role="list" aria-label="Builds per day, this week">              <g aria-hidden="true">                <line class="chart-grid chart-grid-base" x1="0" y1="100%" x2="100%" y2="100%" />                <line class="chart-grid" x1="0" y1="75%" x2="100%" y2="75%" />                <line class="chart-grid" x1="0" y1="50%" x2="100%" y2="50%" />                <line class="chart-grid" x1="0" y1="25%" x2="100%" y2="25%" />                <line class="chart-grid" x1="0" y1="0%" x2="100%" y2="0%" />                <text class="chart-tick chart-tick-x" x="7.143%" y="100%">Mon</text>                <text class="chart-tick chart-tick-x" x="21.429%" y="100%">Tue</text>                <text class="chart-tick chart-tick-x" x="35.714%" y="100%">Wed</text>                <text class="chart-tick chart-tick-x" x="50%" y="100%">Thu</text>                <text class="chart-tick chart-tick-x" x="64.286%" y="100%">Fri</text>                <text class="chart-tick chart-tick-x" x="78.571%" y="100%">Sat</text>                <text class="chart-tick chart-tick-x" x="92.857%" y="100%">Sun</text>              </g>              <g class="chart-point" role="listitem" aria-label="Mon: 42">                <rect class="chart-hit" x="0%" y="0" width="14.286%" height="100%" />                <rect class="chart-bar" x="2.714%" y="47.5%" width="8.857%" height="52.5%" />              </g>              <g class="chart-point" role="listitem" aria-label="Tue: 58">                <rect class="chart-hit" x="14.286%" y="0" width="14.286%" height="100%" />                <rect class="chart-bar" x="17%" y="27.5%" width="8.857%" height="72.5%" />              </g>              <g class="chart-point" role="listitem" aria-label="Wed: 36">                <rect class="chart-hit" x="28.571%" y="0" width="14.286%" height="100%" />                <rect class="chart-bar" x="31.286%" y="55%" width="8.857%" height="45%" />              </g>              <g class="chart-point" role="listitem" aria-label="Thu: 71" aria-current="true">                <rect class="chart-hit" x="42.857%" y="0" width="14.286%" height="100%" />                <rect class="chart-bar" x="45.571%" y="11.25%" width="8.857%" height="88.75%" />              </g>              <g class="chart-point" role="listitem" aria-label="Fri: 0">                <rect class="chart-hit" x="57.143%" y="0" width="14.286%" height="100%" />                <rect class="chart-bar" x="59.857%" y="99.4%" width="8.857%" height="0.6%" />              </g>              <g class="chart-point" role="listitem" aria-label="Sat: 0">                <rect class="chart-hit" x="71.429%" y="0" width="14.286%" height="100%" />                <rect class="chart-bar" x="74.143%" y="99.4%" width="8.857%" height="0.6%" />              </g>              <g class="chart-point" role="listitem" aria-label="Sun: 0">                <rect class="chart-hit" x="85.714%" y="0" width="14.286%" height="100%" />                <rect class="chart-bar" x="88.429%" y="99.4%" width="8.857%" height="0.6%" />              </g>            </svg>          </div>        </figure>      </article>      <article class="sheet sheet-inverse bento-wide flex flex-col justify-between gap-md p(20)">        <div class="flex flex-col gap-3xs">          <h3 class="heading heading-sm fg-text-inverse">Start on the free plan</h3>          <p class="m(0)">Three projects and every feature above. No card needed.</p>        </div>        <div class="flex"><a class="btn btn-sm" href="#start">Create a project</a></div>      </article>    </div>  </section></template>
先选择“平板”,再选择“手机”。布局从四列变为两列,再变为一列,每个区块的跨列范围都以当前列数为限。

#实现方式

  • 按自身宽度确定列数。 容器无法查询自身尺寸,因此 Bento 布局沿用自动网格的做法:用 repeat(auto-fill, …) 设置轨道的最小宽度。宽度达到 48rem 时,轨道最小宽度为总宽度的四分之一;从 28rem 到不足 48rem 时为一半;低于 28rem 时为全宽。因此,auto-fill 只会排出四列、两列或一列。
  • 区块跨度随列数调整。 Bento 布局是一个名为 bento 的尺寸容器,查询的也是这个宽度。bento-wide、bento-tall 和 bento-large 只在布局宽度达到 28rem、有两列可跨时生效。bento-full 在任何宽度下都占满整行。
  • 行高有下限。 每行的最小高度由 --bento-row 设置,默认是 10rem,并可随内容增高。无论内容是什么,高区块都占两行及其间距。
  • 按标记顺序排列区块。 上面六个区块的顺序兼顾四列和两列布局:先放大区块和高区块,再用两个小区块填满高区块旁的一列,最后放两个宽区块。
  • 用组件呈现区块。 分栏卡片在区块较宽时将图片放在文字旁,较窄时将图片放在文字上方。数据由统计指标和低调图表呈现,最后一个区块是页面上唯一的反色面板。

#区块

未添加类名的区块占一个单元格。以下四个部件类可以扩大区块的占用范围。

类名四列时两列时一列时
bento-wide跨两列占满整行一个单元格
bento-tall跨两行跨两行一个单元格
bento-large跨两列、两行占满两整行一个单元格
bento-full占满整行占满整行占满整行

区块

<div class="bento p-lg bg-surface-base fg-text-muted text-2xl font-mono" style="--bento-row: 5rem">  <div class="well flex items-center justify-center bento-large">bento-large</div>  <div class="well flex items-center justify-center bento-tall">bento-tall</div>  <div class="well flex items-center justify-center">One cell</div>  <div class="well flex items-center justify-center">One cell</div>  <div class="well flex items-center justify-center bento-wide">bento-wide</div>  <div class="well flex items-center justify-center">One cell</div>  <div class="well flex items-center justify-center">One cell</div>  <div class="well flex items-center justify-center bento-full">bento-full</div></div>
<div className="bento p-lg bg-surface-base fg-text-muted text-2xl font-mono" style={{ '--bento-row': '5rem' } as React.CSSProperties}>  <div className="well flex items-center justify-center bento-large">bento-large</div>  <div className="well flex items-center justify-center bento-tall">bento-tall</div>  <div className="well flex items-center justify-center">One cell</div>  <div className="well flex items-center justify-center">One cell</div>  <div className="well flex items-center justify-center bento-wide">bento-wide</div>  <div className="well flex items-center justify-center">One cell</div>  <div className="well flex items-center justify-center">One cell</div>  <div className="well flex items-center justify-center bento-full">bento-full</div></div>
<div class="bento p-lg bg-surface-base fg-text-muted text-2xl font-mono" style="--bento-row: 5rem">  <div class="well flex items-center justify-center bento-large">bento-large</div>  <div class="well flex items-center justify-center bento-tall">bento-tall</div>  <div class="well flex items-center justify-center">One cell</div>  <div class="well flex items-center justify-center">One cell</div>  <div class="well flex items-center justify-center bento-wide">bento-wide</div>  <div class="well flex items-center justify-center">One cell</div>  <div class="well flex items-center justify-center">One cell</div>  <div class="well flex items-center justify-center bento-full">bento-full</div></div>
<template>  <div class="bento p-lg bg-surface-base fg-text-muted text-2xl font-mono" style="--bento-row: 5rem">    <div class="well flex items-center justify-center bento-large">bento-large</div>    <div class="well flex items-center justify-center bento-tall">bento-tall</div>    <div class="well flex items-center justify-center">One cell</div>    <div class="well flex items-center justify-center">One cell</div>    <div class="well flex items-center justify-center bento-wide">bento-wide</div>    <div class="well flex items-center justify-center">One cell</div>    <div class="well flex items-center justify-center">One cell</div>    <div class="well flex items-center justify-center bento-full">bento-full</div>  </div></template>
先选择“平板”,再选择“手机”。列数足够时,区块保留设定的跨度。列数不足时,跨度设置失效。

只让少数区块跨行或跨列。如果每个区块都很大,布局就成了区块更大的自动网格。如果没有大区块,就没有优先呈现的内容。

#排列顺序

网格按标记顺序放置区块,每个区块占用前一个区块之后第一个容得下它的位置。宽区块在行尾放不下时会移到下一行,在上一行留下空位。网格保留这个空位,使视觉顺序与标记顺序一致。键盘导航和屏幕阅读器都遵循标记顺序。

编写标记时,请按能排得紧凑的顺序放置区块。对于标志墙或一组没有顺序要求的图片,可以用 bento-dense 让后面的区块向前填补空位。

排列顺序

<div class="flex flex-col gap-md w-full fg-text-muted text-sm">  <p class="eyebrow">bento</p>  <div class="bento" style="--bento-row: 3rem">    <div class="well flex items-center justify-center">1</div>    <div class="well flex items-center justify-center bento-wide">2</div>    <div class="well flex items-center justify-center bento-wide">3</div>    <div class="well flex items-center justify-center">4</div>    <div class="well flex items-center justify-center">5</div>  </div>  <p class="eyebrow">bento bento-dense</p>  <div class="bento bento-dense" style="--bento-row: 3rem">    <div class="well flex items-center justify-center">1</div>    <div class="well flex items-center justify-center bento-wide">2</div>    <div class="well flex items-center justify-center bento-wide">3</div>    <div class="well flex items-center justify-center">4</div>    <div class="well flex items-center justify-center">5</div>  </div></div>
<div className="flex flex-col gap-md w-full fg-text-muted text-sm">  <p className="eyebrow">bento</p>  <div className="bento" style={{ '--bento-row': '3rem' } as React.CSSProperties}>    <div className="well flex items-center justify-center">1</div>    <div className="well flex items-center justify-center bento-wide">2</div>    <div className="well flex items-center justify-center bento-wide">3</div>    <div className="well flex items-center justify-center">4</div>    <div className="well flex items-center justify-center">5</div>  </div>  <p className="eyebrow">bento bento-dense</p>  <div className="bento bento-dense" style={{ '--bento-row': '3rem' } as React.CSSProperties}>    <div className="well flex items-center justify-center">1</div>    <div className="well flex items-center justify-center bento-wide">2</div>    <div className="well flex items-center justify-center bento-wide">3</div>    <div className="well flex items-center justify-center">4</div>    <div className="well flex items-center justify-center">5</div>  </div></div>
<div class="flex flex-col gap-md w-full fg-text-muted text-sm">  <p class="eyebrow">bento</p>  <div class="bento" style="--bento-row: 3rem">    <div class="well flex items-center justify-center">1</div>    <div class="well flex items-center justify-center bento-wide">2</div>    <div class="well flex items-center justify-center bento-wide">3</div>    <div class="well flex items-center justify-center">4</div>    <div class="well flex items-center justify-center">5</div>  </div>  <p class="eyebrow">bento bento-dense</p>  <div class="bento bento-dense" style="--bento-row: 3rem">    <div class="well flex items-center justify-center">1</div>    <div class="well flex items-center justify-center bento-wide">2</div>    <div class="well flex items-center justify-center bento-wide">3</div>    <div class="well flex items-center justify-center">4</div>    <div class="well flex items-center justify-center">5</div>  </div></div>
<template>  <div class="flex flex-col gap-md w-full fg-text-muted text-sm">    <p class="eyebrow">bento</p>    <div class="bento" style="--bento-row: 3rem">      <div class="well flex items-center justify-center">1</div>      <div class="well flex items-center justify-center bento-wide">2</div>      <div class="well flex items-center justify-center bento-wide">3</div>      <div class="well flex items-center justify-center">4</div>      <div class="well flex items-center justify-center">5</div>    </div>    <p class="eyebrow">bento bento-dense</p>    <div class="bento bento-dense" style="--bento-row: 3rem">      <div class="well flex items-center justify-center">1</div>      <div class="well flex items-center justify-center bento-wide">2</div>      <div class="well flex items-center justify-center bento-wide">3</div>      <div class="well flex items-center justify-center">4</div>      <div class="well flex items-center justify-center">5</div>    </div>  </div></template>
托盘中的 Bento 布局宽度不足 28rem 时,每个区块都只占一个单元格,排列时不会在区块之间留下空位。加宽窗口即可看到空位。

第一个 Bento 布局中,宽区块在第一个区块之后留下空位。第二个布局中,第四个区块向前填补了这个空位,视觉上排第二,阅读顺序中仍排第四。

#行

--bento-row 设置每行的最小高度,默认为 10rem。某个区块的文字较多时,该行会随内容增高,旁边的区块也会随之拉伸,避免内容被裁切。区块只放一个数值或一行文字时,可以调低此值,本页的示意图用的是 5rem。区块放图片时,可以调高此值。

--bento-gap 设置区块之间的间距,值为 1rem。计算列数时也会用到这个值,因此间距由这个自定义属性统一设置,不使用间距工具类。

#适用场景

区块特点适用布局
有几种尺寸,部分区块更重要Bento 布局
尺寸一致,数量随内容而定自动网格
各区块的高度由内容决定,例如图库瀑布流
列数由设计指定grid grid-cols(3) 和 grid-col-span(2),搭配容器变体

Bento 布局适合由六到十个区块组成、一次排定的内容。项目列表或搜索结果之类的集合会不断增加,其中没有需要优先突出的区块,适合使用自动网格。

#无障碍

  • 标记中的顺序决定阅读顺序和键盘导航顺序。把最重要的区块写在最前面,仅在顺序无关紧要时使用 bento-dense。
  • 屏幕阅读器不会传达区块大小所体现的重点。把读者最需要的标题放在大区块上,并让每个区块的标题说明其内容,这样只读标题列表也能了解这组区块。
  • 如果整个区块就是一个链接,就把链接本身做成卡片,将 card-interactive 直接加到链接上,避免用拉伸的链接覆盖卡片。

#类名

类名说明
bento网格自身宽度达到 48rem 时为四列,达到 28rem 但低于四列阈值时为两列,再窄则为一列。行高至少为 --bento-row。网格是名为 bento 的尺寸查询容器,不绘制任何视觉样式。
bento-dense后面的网格项会上移,填补前面跨格网格项留下的空位。视觉顺序会与阅读顺序不同,因此只用于顺序无关紧要的内容。与 bento 一同使用
bento-widebento 自身宽度达到 28rem 时,网格项横跨两列。在双列布局中占满整行。
bento-tallbento 自身宽度达到 28rem 时,网格项纵跨两行。
bento-largebento 自身宽度达到 28rem 时,网格项横跨两列、纵跨两行。
bento-full网格项在任意宽度下都占满整行

#自定义属性

属性默认值说明
--bento-row10rem行的最小高度。行高随其中最高的内容增长。
--bento-gap1rem网格项之间的间距,计算列数时计入。

#源码

@master/ui/layouts/bento.css
/* * Bento: a few tiles of different sizes fitted into one box, the way a product's features or a profile's * highlights are shown. It is a layout: it draws no surface; the tiles are cards, sheets or figures. * * What it knows is how many columns there are and how far a tile may span. Both follow the room the bento is * given, never the viewport: four columns from 48rem, two from 28rem, one below. The bento is a size container, * named bento, so the tiles read the same width the columns are counted from. The columns are counted without * a query on the bento itself (a container cannot query its own size): the narrowest a track may be jumps from a * quarter to a half to the whole of the width at those two thresholds, and auto-fill makes as many tracks as * that allows. A pixel is taken off each, so rounding never costs a column. * * A tile takes one cell. bento-wide spans two columns, bento-tall two rows, bento-large both, bento-full the * row. A span never asks for more columns than there are: in two columns a wide tile is the row, and in one * column every tile is one cell. Rows are at least --bento-row tall and grow with what they hold, so a tile * never cuts its words. * * Tiles are placed in the order of the markup, which is also the order a keyboard and a screen reader follow. * The grid does not move a later tile up into a hole: arrange the tiles so they pack, or add bento-dense to a * set whose order means nothing. */@layer components.ui {  .bento {    --bento-row: 10rem;    --bento-gap: 1rem;    display: grid;    grid-template-columns: repeat(auto-fill, minmax(calc(clamp(clamp((100% - var(--bento-gap) * 3) / 4, (48rem - 100%) * 999, (100% - var(--bento-gap)) / 2), (28rem - 100%) * 999, 100%) - 1px), 1fr));    grid-auto-rows: minmax(var(--bento-row), auto);    gap: var(--bento-gap);    min-width: 0;    margin: 0;    padding: 0;    list-style: none;    container: bento / inline-size;    &.bento-dense {      grid-auto-flow: row dense;    }  }  .bento-full {    grid-column: 1 / -1;  }  @container bento (inline-size >= 28rem) {    .bento-wide,    .bento-large {      grid-column: span 2;    }    .bento-tall,    .bento-large {      grid-row: span 2;    }  }}