mask-border

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

mask-border CSS 简写属性允许你在元素的边框边缘创建蒙版。

构成属性

此属性是以下 CSS 属性的简写:

语法

css
/* source | slice */
mask-border: url("border-mask.png") 25;

/* source | slice | repeat */
mask-border: url("border-mask.png") 25 space;

/* source | slice | width */
mask-border: url("border-mask.png") 25 / 35px;

/* source | slice | width | outset | repeat | mode */
mask-border: url("border-mask.png") 25 / 35px / 12px space alpha;

/* Global values */
mask-border: inherit;
mask-border: initial;
mask-border: revert;
mask-border: revert-layer;
mask-border: unset;

<'mask-border-source'>

源图像。参见 mask-border-source

<'mask-border-slice'>

用于将源图像切割成区域的尺寸。最多可指定四个值。参见 mask-border-slice

<'mask-border-width'>

边框蒙版的宽度。最多可指定四个值。参见 mask-border-width

<'mask-border-outset'>

边框蒙版距元素外边缘的距离。最多可指定四个值。参见 mask-border-outset

<'mask-border-repeat'>

定义源图像的边缘区域如何调整以适应边框蒙版的尺寸。最多可指定两个值。参见 mask-border-repeat

<'mask-border-mode'>

定义源图像被视为亮度蒙版还是 alpha 蒙版。参见 mask-border-mode

正式定义

初始值作为简写中的每个属性
应用于所有元素;在 SVG 中,它适用于除 <defs> 元素外的容器元素以及所有图形元素
继承性
百分比作为简写中的每个属性
计算值作为简写中的每个属性
动画类型作为简写中的每个属性
创建层叠上下文

正式语法

mask-border = 
<'mask-border-source'> ||
<'mask-border-slice'> [ / <'mask-border-width'>? [ / <'mask-border-outset'> ]? ]? ||
<'mask-border-repeat'> ||
<'mask-border-mode'>

<mask-border-source> =
none |
<image>

<mask-border-slice> =
[ <number> | <percentage> ]{1,4} fill?

<mask-border-width> =
[ <length-percentage> | <number> | auto ]{1,4}

<mask-border-outset> =
[ <length> | <number> ]{1,4}

<mask-border-repeat> =
[ stretch | repeat | round | space ]{1,2}

<mask-border-mode> =
luminance |
alpha

<image> =
<url> |
<image()> |
<image-set()> |
<cross-fade()> |
<element()> |
<gradient>

<length-percentage> =
<length> |
<percentage>

<image()> =
image( <image-tags>? [ <image-src>? , <color>? ]! )

<image-set()> =
image-set( <image-set-option># )

<cross-fade()> =
cross-fade( <cf-image># )

<element()> =
element( <id-selector> )

<image-tags> =
ltr |
rtl

<image-src> =
<url> |
<string>

<image-set-option> =
[ <image> | <string> ] [ <resolution> || type( <string> ) ]?

<cf-image> =
[ <image> | <color> ] &&
<percentage [0,100]>?

<id-selector> =
<hash-token>

示例

设置基于位图的蒙版边框

在此示例中,我们将用菱形图案遮罩元素的边框。蒙版的来源是一个 90 乘 90 像素的“.png”文件,其中包含三个垂直和水平排列的菱形。

The image used for the mask examples on this page. The mask is a transparent square with three rows of three diamonds each. The diamonds are a very light, almost white, shade of grey. The middle part between the diamonds is also solid grey. The parts between the outside of the diamonds and the edge of the image are transparent.

为了匹配单个菱形的尺寸,我们将使用 90 除以 3,即 30,作为将图像切割成角和边缘区域的值。round 的重复值将使蒙版切片均匀分布,即没有裁剪或间隙。

html
<div class="masked">
  This element is surrounded by a bitmap-based mask border! Pretty neat, isn't
  it?
</div>
css
.masked {
  width: 200px;
  background-color: lavender;
  border: 18px solid salmon;
  padding: 10px;

  -webkit-mask-box-image: url("https://mdn.github.io/shared-assets/images/examples/mask-border-diamonds.png")
    30 fill /          /* slice */
    20px /             /* width */
    1px                /* outset */
    round;             /* repeat */

  mask-border:
    url("https://mdn.github.io/shared-assets/images/examples/mask-border-diamonds.png")
    30 fill /        /* slice */
    20px /           /* width */
    1px              /* outset */
    round;           /* repeat */
}

规范

规范
CSS 蒙版模块 Level 1
# the-mask-border

浏览器兼容性

另见