纹理
在表面铺排圆点、网格、条纹、交叉斜线或棋盘格。
本页内容
纹理是在表面上重复铺排的图案。需要表明某块空白区域的用途时,可在任意元素上使用 .texture。纹理是用低调的单一墨色绘制的背景图,叠在元素原有的底色上。凹槽铺上圆点后,依然呈现为凹槽。
纹理
<div class="well texture flex items-center justify-center h(160)"> <button type="button" class="btn">Publish</button></div><div className="well texture flex items-center justify-center h(160)"> <button type="button" className="btn">Publish</button></div><div class="well texture flex items-center justify-center h(160)"> <button type="button" class="btn">Publish</button></div><template> <div class="well texture flex items-center justify-center h(160)"> <button type="button" class="btn">Publish</button> </div></template>#图案
五种图案各自传达一种区域含义。按含义选择图案,让读者在不同位置看到条纹时,都能作出相同的判断。
图案
<div class="auto-grid auto-grid-fit" style="--auto-grid-min: 6rem"> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture h(96)"></div> <figcaption class="text-xs fg-text-muted">Dots</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-grid h(96)"></div> <figcaption class="text-xs fg-text-muted">Grid</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-stripes h(96)"></div> <figcaption class="text-xs fg-text-muted">Stripes</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-crosshatch h(96)"></div> <figcaption class="text-xs fg-text-muted">Crosshatch</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-checker h(96)"></div> <figcaption class="text-xs fg-text-muted">Checker</figcaption> </figure></div><div className="auto-grid auto-grid-fit" style={{ '--auto-grid-min': '6rem' } as React.CSSProperties}> <figure className="m(0) flex flex-col gap-xs"> <div className="well texture h(96)"></div> <figcaption className="text-xs fg-text-muted">Dots</figcaption> </figure> <figure className="m(0) flex flex-col gap-xs"> <div className="well texture texture-grid h(96)"></div> <figcaption className="text-xs fg-text-muted">Grid</figcaption> </figure> <figure className="m(0) flex flex-col gap-xs"> <div className="well texture texture-stripes h(96)"></div> <figcaption className="text-xs fg-text-muted">Stripes</figcaption> </figure> <figure className="m(0) flex flex-col gap-xs"> <div className="well texture texture-crosshatch h(96)"></div> <figcaption className="text-xs fg-text-muted">Crosshatch</figcaption> </figure> <figure className="m(0) flex flex-col gap-xs"> <div className="well texture texture-checker h(96)"></div> <figcaption className="text-xs fg-text-muted">Checker</figcaption> </figure></div><div class="auto-grid auto-grid-fit" style="--auto-grid-min: 6rem"> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture h(96)"></div> <figcaption class="text-xs fg-text-muted">Dots</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-grid h(96)"></div> <figcaption class="text-xs fg-text-muted">Grid</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-stripes h(96)"></div> <figcaption class="text-xs fg-text-muted">Stripes</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-crosshatch h(96)"></div> <figcaption class="text-xs fg-text-muted">Crosshatch</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-checker h(96)"></div> <figcaption class="text-xs fg-text-muted">Checker</figcaption> </figure></div><template> <div class="auto-grid auto-grid-fit" style="--auto-grid-min: 6rem"> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture h(96)"></div> <figcaption class="text-xs fg-text-muted">Dots</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-grid h(96)"></div> <figcaption class="text-xs fg-text-muted">Grid</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-stripes h(96)"></div> <figcaption class="text-xs fg-text-muted">Stripes</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-crosshatch h(96)"></div> <figcaption class="text-xs fg-text-muted">Crosshatch</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-checker h(96)"></div> <figcaption class="text-xs fg-text-muted">Checker</figcaption> </figure> </div></template>| 类名 | 含义 | 用途 |
|---|---|---|
texture | 开放的展示区域 | 作为组件示例、画布或示意图的背景 |
texture texture-grid | 带尺度参照的区域 | 需要辨别位置的画布,例如编辑器、平面图或布局教程中的画布 |
texture texture-stripes | 预留空白的区域 | 栏间空隙、留白、空槽位或图片占位区 |
texture texture-crosshatch | 不可用的区域 | 不可用的时段、不开放的日期或超出边界的范围 |
texture texture-checker | 完全透明 | 透明图片或带 alpha 通道的颜色下方的背景 |
文字应始终避开纹理。图案穿过字形会降低可读性,因此应把说明文字放在纹理区域旁,或放在覆盖其上的面板上。
#预留与不可用
条纹和交叉斜线区分两种空白状态。条纹表示槽位暂时留空,之后可以填入内容。交叉斜线表示槽位不可选。也要用文字传达同样的含义,因为有些人无法感知图案。此处还将关闭的时段设为禁用,并为其提供名称。
预留与不可用
<div class="sheet grid grid-cols(4) gap-xs p-xs"> <button type="button" class="btn btn-quiet h(88)">9:00</button> <button type="button" class="btn btn-quiet h(88)">10:00</button> <div class="well texture texture-stripes h(88)" role="img" aria-label="11:00, kept free"></div> <div class="well texture texture-crosshatch h(88)" role="img" aria-label="12:00, closed"></div></div><p class="m(0) mt-md text-xs fg-text-muted">11:00 is kept free. The office is closed at 12:00.</p><> <div className="sheet grid grid-cols(4) gap-xs p-xs"> <button type="button" className="btn btn-quiet h(88)">9:00</button> <button type="button" className="btn btn-quiet h(88)">10:00</button> <div className="well texture texture-stripes h(88)" role="img" aria-label="11:00, kept free"></div> <div className="well texture texture-crosshatch h(88)" role="img" aria-label="12:00, closed"></div> </div> <p className="m(0) mt-md text-xs fg-text-muted"> 11:00 is kept free. The office is closed at 12:00. </p></><div class="sheet grid grid-cols(4) gap-xs p-xs"> <button type="button" class="btn btn-quiet h(88)">9:00</button> <button type="button" class="btn btn-quiet h(88)">10:00</button> <div class="well texture texture-stripes h(88)" role="img" aria-label="11:00, kept free"></div> <div class="well texture texture-crosshatch h(88)" role="img" aria-label="12:00, closed"></div></div><p class="m(0) mt-md text-xs fg-text-muted">11:00 is kept free. The office is closed at 12:00.</p><template> <div class="sheet grid grid-cols(4) gap-xs p-xs"> <button type="button" class="btn btn-quiet h(88)">9:00</button> <button type="button" class="btn btn-quiet h(88)">10:00</button> <div class="well texture texture-stripes h(88)" role="img" aria-label="11:00, kept free"></div> <div class="well texture texture-crosshatch h(88)" role="img" aria-label="12:00, closed"></div> </div> <p class="m(0) mt-md text-xs fg-text-muted">11:00 is kept free. The office is closed at 12:00.</p></template>#透明度
棋盘格用作含有透明部分的内容的背景。把图片放在棋盘格上,让方格透过透明部分显现。此处可以从标志的镂空处看到方格。
透明度
<div class="well texture texture-checker flex items-center justify-center w(240) h(136) fg-text-strong"> <svg width="80" height="80" viewBox="0 0 96 96" role="img" aria-label="A square mark with a round hole"> <path fill="currentColor" fill-rule="evenodd" d="M20 8h56a12 12 0 0 1 12 12v56a12 12 0 0 1-12 12H20A12 12 0 0 1 8 76V20A12 12 0 0 1 20 8Zm28 18a22 22 0 1 0 0 44 22 22 0 0 0 0-44Z" /> </svg></div><div className="well texture texture-checker flex items-center justify-center w(240) h(136) fg-text-strong"> <svg width="80" height="80" viewBox="0 0 96 96" role="img" aria-label="A square mark with a round hole"> <path fill="currentColor" fillRule="evenodd" d="M20 8h56a12 12 0 0 1 12 12v56a12 12 0 0 1-12 12H20A12 12 0 0 1 8 76V20A12 12 0 0 1 20 8Zm28 18a22 22 0 1 0 0 44 22 22 0 0 0 0-44Z" /> </svg></div><div class="well texture texture-checker flex items-center justify-center w(240) h(136) fg-text-strong"> <svg width="80" height="80" viewBox="0 0 96 96" role="img" aria-label="A square mark with a round hole"> <path fill="currentColor" fill-rule="evenodd" d="M20 8h56a12 12 0 0 1 12 12v56a12 12 0 0 1-12 12H20A12 12 0 0 1 8 76V20A12 12 0 0 1 20 8Zm28 18a22 22 0 1 0 0 44 22 22 0 0 0 0-44Z" /> </svg></div><template> <div class="well texture texture-checker flex items-center justify-center w(240) h(136) fg-text-strong"> <svg width="80" height="80" viewBox="0 0 96 96" role="img" aria-label="A square mark with a round hole"> <path fill="currentColor" fill-rule="evenodd" d="M20 8h56a12 12 0 0 1 12 12v56a12 12 0 0 1-12 12H20A12 12 0 0 1 8 76V20A12 12 0 0 1 20 8Zm28 18a22 22 0 1 0 0 44 22 22 0 0 0 0-44Z" /> </svg> </div></template>#尺寸、粗细与墨色
可在应用图案的元素上用三个自定义属性调整图案。--texture-size 控制单个图案单元的边长,--texture-weight 控制圆点半径或线条宽度,--texture-ink 控制图案颜色。主题可通过 --color-texture 统一设置所有纹理的墨色。
纹理应比其上的内容更低调。用于展示组件示例时,稀疏纤细的图案足以衬出示例边缘,过密的图案会分散对示例的注意力。
尺寸、粗细与墨色
<div class="auto-grid auto-grid-fit" style="--auto-grid-min: 9rem"> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture h(96)" style="--texture-size: 20px"></div> <figcaption class="text-xs fg-text-muted">A 20px tile</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-stripes h(96)" style="--texture-weight: 1px; --texture-size: 12px"></div> <figcaption class="text-xs fg-text-muted">A 1px stripe in a 12px tile</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-grid h(96)" style="--texture-ink: var(--color-line-hair)"></div> <figcaption class="text-xs fg-text-muted">The hairline's ink</figcaption> </figure></div><div className="auto-grid auto-grid-fit" style={{ '--auto-grid-min': '9rem' } as React.CSSProperties}> <figure className="m(0) flex flex-col gap-xs"> <div className="well texture h(96)" style={{ '--texture-size': '20px' } as React.CSSProperties}></div> <figcaption className="text-xs fg-text-muted">A 20px tile</figcaption> </figure> <figure className="m(0) flex flex-col gap-xs"> <div className="well texture texture-stripes h(96)" style={{ '--texture-weight': '1px', '--texture-size': '12px' } as React.CSSProperties}></div> <figcaption className="text-xs fg-text-muted">A 1px stripe in a 12px tile</figcaption> </figure> <figure className="m(0) flex flex-col gap-xs"> <div className="well texture texture-grid h(96)" style={{ '--texture-ink': 'var(--color-line-hair)' } as React.CSSProperties}></div> <figcaption className="text-xs fg-text-muted">The hairline's ink</figcaption> </figure></div><div class="auto-grid auto-grid-fit" style="--auto-grid-min: 9rem"> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture h(96)" style="--texture-size: 20px"></div> <figcaption class="text-xs fg-text-muted">A 20px tile</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-stripes h(96)" style="--texture-weight: 1px; --texture-size: 12px"></div> <figcaption class="text-xs fg-text-muted">A 1px stripe in a 12px tile</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-grid h(96)" style="--texture-ink: var(--color-line-hair)"></div> <figcaption class="text-xs fg-text-muted">The hairline's ink</figcaption> </figure></div><template> <div class="auto-grid auto-grid-fit" style="--auto-grid-min: 9rem"> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture h(96)" style="--texture-size: 20px"></div> <figcaption class="text-xs fg-text-muted">A 20px tile</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-stripes h(96)" style="--texture-weight: 1px; --texture-size: 12px"></div> <figcaption class="text-xs fg-text-muted">A 1px stripe in a 12px tile</figcaption> </figure> <figure class="m(0) flex flex-col gap-xs"> <div class="well texture texture-grid h(96)" style="--texture-ink: var(--color-line-hair)"></div> <figcaption class="text-xs fg-text-muted">The hairline's ink</figcaption> </figure> </div></template>条纹在正方形图案单元内倾斜 45°,因此相邻条纹的间距为单元边长除以 √2。默认边长为 8px 时,间距为 5.7px。单元边长应取整数像素,以免相邻单元的线条错位。
图案单元从区域中心开始铺排,因此无论区域尺寸如何,相对两侧的边缘都会以相同方式裁切图案。设置 background-position 可从角落开始铺排。
#渐隐
texture-fade 让图案朝边缘逐渐淡出,可用作标题背景。它使用的遮罩也会淡化元素内的内容,因此应将它应用到内容后方的独立元素上,并对辅助技术隐藏该元素。
渐隐
<div class="relative flex flex-col items-center justify-center gap-md h(192)"> <div class="texture texture-grid texture-fade absolute inset(0)" aria-hidden="true"></div> <h3 class="relative m(0) text-xl fg-text-strong">Ship the first draft</h3> <button type="button" class="relative btn btn-primary">Start a project</button></div><div className="relative flex flex-col items-center justify-center gap-md h(192)"> <div className="texture texture-grid texture-fade absolute inset(0)" aria-hidden="true"></div> <h3 className="relative m(0) text-xl fg-text-strong">Ship the first draft</h3> <button type="button" className="relative btn btn-primary">Start a project</button></div><div class="relative flex flex-col items-center justify-center gap-md h(192)"> <div class="texture texture-grid texture-fade absolute inset(0)" aria-hidden="true"></div> <h3 class="relative m(0) text-xl fg-text-strong">Ship the first draft</h3> <button type="button" class="relative btn btn-primary">Start a project</button></div><template> <div class="relative flex flex-col items-center justify-center gap-md h(192)"> <div class="texture texture-grid texture-fade absolute inset(0)" aria-hidden="true"></div> <h3 class="relative m(0) text-xl fg-text-strong">Ship the first draft</h3> <button type="button" class="relative btn btn-primary">Start a project</button> </div></template>#叠层
纹理会替换表面原有的背景图,元素保留原有底色。若要同时保留另一张图像,或用图案裁出形状,可从应用该类的元素上读取 --texture-image,该属性公开了图案。
.texture.stage { background-image: var(--texture-image), linear-gradient(var(--color-surface-raised), var(--color-surface-raised-low)); background-size: var(--texture-size) var(--texture-size), auto;}交叉斜线由两层组成,因此要为两层分别设置尺寸。
#无障碍
纹理属于图案,在强制颜色模式下会被移除。任何含义都不能仅靠纹理传达。
- 仅作装饰的区域无需额外处理。专用于承载纹理的元素应设置
aria-hidden="true"。 - 如果纹理表示预留、关闭或透明等状态,应同时用看得见的文字说明:放在区域旁或区域内,强制颜色模式也会保留这些文字。在区域本身设置
role="img"和aria-label可以让辅助技术读出名称,但屏幕上看不到,因此不能代替文字。 - 不可用的控件应先设置
disabled。交叉斜线仅补充呈现该属性已表达的状态。
#类名
| 类名 | 说明 |
|---|---|
texture | 点阵:每个平铺单元一个点,用作示例的背景 |
texture-grid | 用方格线标示有度量尺度的区域。与 texture 一同使用 |
texture-stripes | 用于标示刻意留空的区域,例如栏间距、净空区或空槽,以斜向细线填充与 texture 一同使用 |
texture-crosshatch | 用两个方向交叉的细线标示不可用区域,例如禁止选择的时段或超出边界的范围。与 texture 一同使用 |
texture-checker | 用交错方格为透明内容铺底与 texture 一同使用 |
texture-fade | 纹理向边缘逐渐淡出。它也会遮罩元素内的内容,因此应将它放在独立的元素上与 texture 一同使用 |
#自定义属性
| 属性 | 默认值 | 说明 |
|---|---|---|
--texture-ink | var(--color-texture) | 标记的颜色。线条和方块以该颜色的一半不透明度绘制。在 texture 上设置 |
--texture-size | 12px | 单个图案单元的边长。点阵用 12px,网格用 24px,条纹和交叉线用 8px,棋盘格用 16px。在 texture 上设置 |
--texture-weight | 1px | 控制圆点的半径或线条的宽度。条纹线宽为 .5px,棋盘格不使用此设置。在 texture 上设置 |
--texture-image | 纹理本身,可铺在另一张图像下方,也可用作遮罩。交叉网纹由两层组成在 texture 上设置 |