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 布局中,宽区块在第一个区块之后留下空位。第二个布局中,第四个区块向前填补了这个空位,视觉上排第二,阅读顺序中仍排第四。
#行
--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-wide | bento 自身宽度达到 28rem 时,网格项横跨两列。在双列布局中占满整行。 |
bento-tall | bento 自身宽度达到 28rem 时,网格项纵跨两行。 |
bento-large | bento 自身宽度达到 28rem 时,网格项横跨两列、纵跨两行。 |
bento-full | 网格项在任意宽度下都占满整行 |
#自定义属性
| 属性 | 默认值 | 说明 |
|---|---|---|
--bento-row | 10rem | 行的最小高度。行高随其中最高的内容增长。 |
--bento-gap | 1rem | 网格项之间的间距,计算列数时计入。 |
#相关内容
- 自动网格根据可用宽度自动安排尽可能多的等宽列。
- 瀑布流将高度各异的内容块紧密排入等宽列,避免因高度不齐在内容块下方留下空白。
- 卡片凸起的面板,部件会随卡片的可用空间调整。
- 统计指标显示一项指标的数值、含义和变化:低调的标签、醒目的数值和变化幅度。
- 图表用一个自适应宽度的 SVG 绘制数据,支持从折线图到旭日图的二十多种形式。
- 表面托盘、凸起面板与凹槽构成所有组件共用的材质层级。