导航

v2.1.0
材质

纹理

在表面铺排圆点、网格、条纹、交叉斜线或棋盘格。

本页内容

纹理是在表面上重复铺排的图案。需要表明某块空白区域的用途时,可在任意元素上使用 .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-inkvar(--color-texture)标记的颜色。线条和方块以该颜色的一半不透明度绘制。在 texture 上设置
--texture-size12px单个图案单元的边长。点阵用 12px,网格用 24px,条纹和交叉线用 8px,棋盘格用 16px。在 texture 上设置
--texture-weight1px控制圆点的半径或线条的宽度。条纹线宽为 .5px,棋盘格不使用此设置。在 texture 上设置
--texture-image纹理本身,可铺在另一张图像下方,也可用作遮罩。交叉网纹由两层组成在 texture 上设置

#源码

@master/ui/components/texture.css
/* * Texture: one drawing repeated across the face of a surface. It is a background image in the theme's * texture ink, tiled at --texture-size, so it stands on whatever color the element already has and takes * the place of that face's own image only. Each texture says one thing about the room it fills: dots are an * open stage, a grid is measured room, stripes are room kept empty, a crosshatch is room that cannot be used * and a checker is nothing at all, the ground under something transparent. * * Every mark is a hard-stopped gradient, so one tile holds the drawing and --texture-weight is its real * thickness. Stripes turn 45° in a square tile, which sets them the tile's side over √2 apart. Tiles are counted * from the middle of the room, so the drawing is cut the same way at opposite edges. Where the browser has * round(), the middle is snapped to a whole pixel: a tile centered in a room of odd width would otherwise land * on half a pixel and blur every mark. The drawing is published as --texture-image, to lay under another image * or to use as a mask. * * In forced colors the drawing is removed: a texture never carries a meaning alone. */@layer components.ui {  .texture {    --texture-ink: var(--color-texture);    --texture-size: 12px;    --texture-weight: 1px;    /* Dots: one point in the middle of each tile, with a quarter pixel of edge so it stays round. */    --texture-image: radial-gradient(circle, var(--texture-ink) var(--texture-weight), transparent calc(var(--texture-weight) + .25px));    background-image: var(--texture-image);    background-size: var(--texture-size) var(--texture-size);    background-position: center;    background-position: round(50%, 1px) round(50%, 1px);    /* A rule along the top and the start of each tile. Rules cover more than points do, so they take half the ink. */    &.texture-grid {      --texture-size: 24px;      --texture-image: conic-gradient(from 90deg at var(--texture-weight) var(--texture-weight), transparent 25%, color-mix(in oklab, var(--texture-ink) 50%, transparent) 0);    }    /* Two hairlines a tile: one through its corners, one across its middle. */    &.texture-stripes {      --texture-size: 8px;      --texture-weight: .5px;      --texture-image: linear-gradient(135deg, var(--texture-ink) 0 var(--texture-weight), transparent 0 50%, var(--texture-ink) 0 calc(50% + var(--texture-weight)), transparent 0);    }    /* The same hairlines both ways. This drawing is two layers. */    &.texture-crosshatch {      --texture-size: 8px;      --texture-weight: .5px;      --texture-image:        linear-gradient(135deg, var(--texture-ink) 0 var(--texture-weight), transparent 0 50%, var(--texture-ink) 0 calc(50% + var(--texture-weight)), transparent 0),        linear-gradient(45deg, var(--texture-ink) 0 var(--texture-weight), transparent 0 50%, var(--texture-ink) 0 calc(50% + var(--texture-weight)), transparent 0);    }    /* Two squares of four. Squares cover half the face, so they take half the ink. */    &.texture-checker {      --texture-size: 16px;      --texture-image: conic-gradient(color-mix(in oklab, var(--texture-ink) 50%, transparent) 25%, transparent 0 50%, color-mix(in oklab, var(--texture-ink) 50%, transparent) 0 75%, transparent 0);    }    /* The drawing thins out toward the edges. A mask fades what the element holds too, so it goes on an element of its own. */    &.texture-fade {      mask-image: radial-gradient(farthest-side, black 30%, transparent);    }    @media (forced-colors: active) {      background-image: none;    }  }}