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
|
---
title: clip-path
slug: Web/SVG/Attribute/clip-path
tags:
- SVG
- SVG 属性
translation_of: Web/SVG/Attribute/clip-path
---
<div>{{SVGRef}}</div>
<p>元素的表现属性 <strong><code>clip-path</code></strong> 为其定义或关联一条剪切路径。</p>
<p class="note"><strong>注意:</strong><code>clip-path</code> 是一个表现属性,可以作为 CSS 属性使用。</p>
<p>作为一种表现属性,<code>clip-path</code> 可以用于任何元素,不过效果最明显的是下列十九种元素:{{SVGElement('a')}}, {{SVGElement('circle')}}, {{SVGElement('clipPath')}}, {{SVGElement('ellipse')}}, {{SVGElement('g')}}, {{SVGElement('glyph')}}, {{SVGElement('image')}}, {{SVGElement('line')}}, {{SVGElement('marker')}}, {{SVGElement('mask')}}, {{SVGElement('path')}}, {{SVGElement('pattern')}}, {{SVGElement('polygon')}}, {{SVGElement('polyline')}}, {{SVGElement('rect')}}, {{SVGElement('svg')}}, {{SVGElement('symbol')}}, {{SVGElement('text')}}, {{SVGElement('use')}}</p>
<div id="topExample">
<div class="hidden">
<pre class="brush: css">html,body,svg { height:100% }</pre>
</div>
<pre class="brush: html"><svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<clipPath id="myClip" clipPathUnits="objectBoundingBox">
<circle cx=".5" cy=".5" r=".5" />
</clipPath>
<!-- 左上:应用自定义的剪切路径 -->
<rect x="1" y="1" width="8" height="8" stroke="green"
clip-path="url(#myClip)" />
<!-- 右上:应用 CSS 基本形状和 fill-box 几何。
实质上和自定义剪切路径并把 clipPathUnits
设成 objectBoundingBox 一样 -->
<rect x="11" y="1" width="8" height="8" stroke="green"
clip-path="circle() fill-box" />
<!-- 左下 -->
<rect x="1" y="11" width="8" height="8" stroke="green"
clip-path="circle() stroke-box" />
<!-- 右下:应用CSS基本形状和 view-box 几何。
实质上和自定义剪切路径并把 clipPathUnits
设成 userSpaceOnUse 一样 -->
<rect x="11" y="11" width="8" height="8" stroke="green"
clip-path="circle() view-box" />
</svg></pre>
<p>{{EmbedLiveSample('topExample', '100%', 200)}}</p>
</div>
<h2 id="Usage_notes">Usage notes</h2>
<table class="properties">
<tbody>
<tr>
<th scope="row">值</th>
<td>{{cssxref('url')}} | [ {{cssxref('basic-shape')}} || <code><geometry-box></code> ] | <code>none</code></td>
</tr>
<tr>
<th scope="row">默认值</th>
<td><code>none</code></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>是</td>
</tr>
</tbody>
</table>
<dl>
<dt><geometry-box></dt>
<dd>geometry-box 是应用 {{cssxref('basic-shape')}} 的额外信息,用于区分 CSS 基本形状如何应用于元素上:<code>fill-box</code> 表示将对象的包围框作为参照框;<code>stroke-box</code> 表示将对象的包围框加上描边的范围作为参照框;<code>view-box</code> 表示使用最近的 SVG 视窗作为参照框。</dd>
</dl>
<p class="note"><strong>注意:</strong>clip-path 语法的更多细节可参考 CSS 属性 {{cssxref('clip-path')}} 的参考页面。</p>
<h2 id="Browser_Compatibility" name="Browser_Compatibility">浏览器兼容</h2>
<p>{{Compat("svg.attributes.presentation.clip-path")}}</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", "#the-clip-path", 'clip-path')}}</td>
<td>{{Spec2('CSS Masks')}}</td>
<td>Extends its application to HTML elements. The <code>clip-path</code> property replaces the deprecated {{cssxref("clip")}} property.</td>
</tr>
<tr>
<td>{{SpecName('SVG1.1', 'masking.html#ClipPathProperty', 'clip-path')}}</td>
<td>{{Spec2('SVG1.1')}}</td>
<td>Initial definition (applies to SVG elements only).</td>
</tr>
</tbody>
</table>
<h2 id="See_also">See also</h2>
<ul>
<li>The CSS {{cssxref("clip-path")}} property</li>
</ul>
|