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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
---
title: background-clip
slug: Web/CSS/background-clip
tags:
- CSS
- CSS Background
- CSS Property
- Clip
- Reference
translation_of: Web/CSS/background-clip
---
<div>{{CSSRef}}</div>
<p><code>background-clip</code> 设置元素的背景(背景图片或颜色)是否延伸到边框、内边距盒子、内容盒子下面。</p>
<div>{{EmbedInteractiveExample("pages/css/background-clip.html")}}</div>
<p class="hidden">此交互样例的源代码被储存在GitHub库中.如果你想要对此交互样例工程有代码贡献,请点击 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a>并向我们发送拉取请求</p>
<p>如果没有设置背景图片({{cssxref("background-image")}})或背景颜色({{cssxref("background-color")}}),那么这个属性只有在边框( {{cssxref("border")}})被设置为非固实(soild)、透明或半透明时才能看到视觉效果(与 {{cssxref("border-style")}} 或 {{cssxref("border-image")}} 有关),否则,本属性产生的样式变化会被边框覆盖。</p>
<h2 id="语法">语法</h2>
<pre class="brush:css no-line-numbers notranslate">/* Keyword values */
background-clip: border-box;
background-clip: padding-box;
background-clip: content-box;
background-clip: text;
/* Global values */
background-clip: inherit;
background-clip: initial;
background-clip: unset;
</pre>
<h3 id="值">值</h3>
<dl>
<dt><code>border-box</code></dt>
<dd>背景延伸至边框外沿(但是在边框下层)。</dd>
<dt><code>padding-box</code></dt>
<dd>背景延伸至内边距({{cssxref("padding")}})外沿。不会绘制到边框处。</dd>
<dt><code>content-box</code></dt>
<dd>背景被裁剪至内容区(content box)外沿。</dd>
<dt><code>text</code> {{experimental_inline}}</dt>
<dd>背景被裁剪成文字的前景色。</dd>
</dl>
<h3 id="标准语法">标准语法</h3>
{{csssyntax}}
<h2 id="示例">示例</h2>
<h4 id="HTML">HTML</h4>
<pre class="brush: html notranslate"><p class="border-box">The background extends behind the border.</p>
<p class="padding-box">The background extends to the inside edge of the border.</p>
<p class="content-box">The background extends only to the edge of the content box.</p>
<p class="text">The background is clipped to the foreground text.</p>
</pre>
<h4 id="CSS">CSS</h4>
<pre class="brush: css notranslate">p {
border: .8em darkviolet;
border-style: dotted double;
margin: 1em 0;
padding: 1.4em;
background: linear-gradient(60deg, red, yellow, red, yellow, red);
font: 900 1.2em sans-serif;
text-decoration: underline;
}
.border-box { background-clip: border-box; }
.padding-box { background-clip: padding-box; }
.content-box { background-clip: content-box; }
.text {
background-clip: text;
-webkit-background-clip: text;
color: rgba(0,0,0,.2);
}</pre>
<h4 id="结果">结果</h4>
<p>{{EmbedLiveSample('Examples', 600, 580)}}</p>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('CSS3 Backgrounds', '#the-background-clip', 'background-clip')}}</td>
<td>{{Spec2('CSS3 Backgrounds')}}</td>
<td>Initial definition.</td>
</tr>
<tr>
<td>{{SpecName('CSS4 Backgrounds', '#background-clip', 'background-clip')}}</td>
<td>{{Spec2('CSS4 Backgrounds')}}</td>
<td>Add <code>text</code> value.</td>
</tr>
</tbody>
</table>
<p>{{cssinfo}}</p>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("css.properties.background-clip")}}</p>
<h2 id="参见">参见</h2>
<ul>
<li>The {{cssxref("clip-path")}} property creates a clipping region that defines what part of an <em>entire element</em> should be displayed.</li>
<li>Background properties: {{cssxref("background")}}, {{cssxref("background-color")}}, {{cssxref("background-image")}}</li>
<li><a href="/en-US/docs/Web/CSS/box_model">Introduction to the CSS box model</a></li>
</ul>
|