aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/mask-border/index.html
blob: ecd3d4481491cd2d24b615db599db18344cac7d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
title: mask-border
slug: Web/CSS/mask-border
translation_of: Web/CSS/mask-border
---
<div>{{cssref}}{{SeeCompatTable}}</div>

<p><a href="/en-US/docs/Web/CSS">CSS</a> 属性 <strong><code>mask-border</code></strong> 允许你创建一个紧贴元素边框边缘的mask.</p>

<p>该属性为以下属性的<a href="/en-US/docs/Web/CSS/Shorthand_properties">简写</a>{{cssxref("mask-border-source")}}, {{cssxref("mask-border-slice")}}, {{cssxref("mask-border-width")}}, {{cssxref("mask-border-outset")}}, {{cssxref("mask-border-repeat")}}, and {{cssxref("mask-border-mode")}}. 与其他简写的属性一样,任何一个漏写的子属性,将会被设置为他们的<a href="/en-US/docs/Web/CSS/initial_value">初始值</a>.</p>

<h2 id="语法">语法</h2>

<pre class="brush: css no-line-numbers">/* 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;
</pre>

<h3 id="Values">Values</h3>

<dl>
 <dt><code>&lt;'mask-border-source'&gt;</code></dt>
 <dd>该属性为源图像. 参见 {{cssxref("mask-border-source")}}.</dd>
 <dt><code>&lt;'mask-border-slice'&gt;</code></dt>
 <dd>将源图像切割后的区域的尺寸,最多可指定四个值. 参见 {{cssxref("mask-border-slice")}}.</dd>
 <dt><code>&lt;'mask-border-width'&gt;</code></dt>
 <dd>边框mask的宽度. 最多可指定四个值. 参见 {{cssxref("mask-border-width")}}.</dd>
 <dt><code>&lt;'mask-border-outset'&gt;</code></dt>
 <dd>边框mask距离元素外边界的距离. 最多可指定四个值. 参见 {{cssxref("mask-border-outset")}}.</dd>
 <dt><code>&lt;'mask-border-repeat'&gt;</code></dt>
 <dd>定义如何调整源图像的边缘区域以适应边框mask的尺寸. 最多可指定四个值. 参见 {{cssxref("mask-border-repeat")}}.</dd>
 <dt><code>&lt;'mask-border-mode'&gt;</code></dt>
 <dd>定义是否将源图片设置为明亮度mask,或者透明度mask. 参见 {{cssxref("mask-border-mode")}}.</dd>
</dl>

<h3 id="形式语法">形式语法</h3>

<pre class="syntaxbox">{{csssyntax}}</pre>

<h2 id="范例">范例</h2>

<h3 id="Bitmap">Bitmap</h3>

<p>在此范例中,我们将使用钻石图案来给元素添加mask. mask的源文件是一个 ".png" 文件,大小为 90像素 * 90 像素,三颗钻石垂直和水平交叉;</p>

<p><img alt="" src="https://mdn.mozillademos.org/files/15836/mask-border-diamonds.png" style="height: 90px; width: 90px;"></p>

<h4 id="HTML">HTML</h4>

<pre class="brush: html">&lt;div id="bitmap"&gt;This element is surrounded by a bitmap-based mask border! Pretty neat, isn't it?&lt;/div&gt;</pre>

<h4 id="CSS">CSS</h4>

<p>为了适应一个钻石的大小,我们使用90/3 或者30,用于设置将图像切割至边角以及边缘区域的值,并设置repeat属性为 <code>round</code> ,该属性使得切片均匀贴合,例如:没有裁剪和空隙.</p>

<pre class="brush: css">div {
  width: 200px;
  background-color: lavender;
  border: 18px solid salmon;
  padding: 10px;

  mask-border:
    url("https://mdn.mozillademos.org/files/15836/mask-border-diamonds.png")  /* source */
    30 /         /* slice */
    36px 18px    /* width */
    round;       /* repeat */
}
</pre>

<h4 id="Result">Result</h4>

<p>{{EmbedLiveSample("Example")}}</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("CSS Masks", "#propdef-mask-border", "mask-border")}}</td>
   <td>{{Spec2("CSS Masks")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<p>{{cssinfo}}</p>

<h2 id="浏览器兼容性Edit">浏览器兼容性<a class="button section-edit only-icon" href="https://developer.mozilla.org/en-US/docs/Web/CSS/border-image$edit#Browser_compatibility" rel="nofollow, noindex"><span>Edit</span></a></h2>

<p><span>TBD</span></p>