-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
156 lines (129 loc) · 4.15 KB
/
index.md
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
---
title: spreadMethod
slug: Web/SVG/Attribute/spreadMethod
page-type: svg-attribute
browser-compat: svg.elements.linearGradient.spreadMethod
---
{{SVGRef}}
The **`spreadMethod`** attribute determines how a shape is filled beyond the defined edges of a gradient.
You can use this attribute with the following SVG elements:
- {{SVGElement("linearGradient")}}
- {{SVGElement("radialGradient")}}
## Context notes
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code>pad</code> | <code>reflect</code> | <code>repeat</code></td>
</tr>
<tr>
<th scope="row">Initial value</th>
<td><code>pad</code></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>Yes</td>
</tr>
</tbody>
</table>
- `pad`
- : This value indicates that the final color of the gradient fills the shape beyond the gradient's edges.
- `reflect`
- : This value indicates that the gradient repeats in reverse beyond its edges.
- `repeat`
- : This value specifies that the gradient repeats in the original order beyond its edges.
### Defining a gradient's edges
By default, a gradient reaches to the edges of the shape being filled. To see the effects of this attribute, you will need to set the size of the gradient smaller than the shape.
In the case of a linear gradient, the edges may be defined as a rectangle by the `x1`, `x2`, `y1` and `y2` attributes. In the case of a radial gradient, the edges may be defined as outer and inner circles by the `cx`, `cy` and `r` (outer) and `fx`, `fy` and `fr` (inner) attributes.
## Examples of spreadMethod with linear gradients
### SVG
```html
<svg width="220" height="150" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="PadGradient" x1="33%" x2="67%">
<stop offset="0%" stop-color="fuchsia" />
<stop offset="100%" stop-color="orange" />
</linearGradient>
<linearGradient
id="ReflectGradient"
spreadMethod="reflect"
x1="33%"
x2="67%">
<stop offset="0%" stop-color="fuchsia" />
<stop offset="100%" stop-color="orange" />
</linearGradient>
<linearGradient id="RepeatGradient" spreadMethod="repeat" x1="33%" x2="67%">
<stop offset="0%" stop-color="fuchsia" />
<stop offset="100%" stop-color="orange" />
</linearGradient>
</defs>
<rect fill="url(#PadGradient)" x="10" y="0" width="200" height="40" />
<rect fill="url(#ReflectGradient)" x="10" y="50" width="200" height="40" />
<rect fill="url(#RepeatGradient)" x="10" y="100" width="200" height="40" />
</svg>
```
### Result
{{EmbedLiveSample('Examples_of_spreadMethod_with_linear_gradients')}}
Notice that the middle third of each gradient is the same. The outer thirds show the difference between the three spread methods.
## Examples of spreadMethod with radial gradients
### SVG
```html
<svg width="340" height="120" xmlns="http://www.w3.org/2000/svg">
<defs>
<radialGradient
id="RadialPadGradient"
cx="75%"
cy="25%"
r="33%"
fx="64%"
fy="18%"
fr="17%">
<stop offset="0%" stop-color="fuchsia" />
<stop offset="100%" stop-color="orange" />
</radialGradient>
<radialGradient
id="RadialReflectGradient"
spreadMethod="reflect"
cx="75%"
cy="25%"
r="33%"
fx="64%"
fy="18%"
fr="17%">
<stop offset="0%" stop-color="fuchsia" />
<stop offset="100%" stop-color="orange" />
</radialGradient>
<radialGradient
id="RadialRepeatGradient"
spreadMethod="repeat"
cx="75%"
cy="25%"
r="33%"
fx="64%"
fy="18%"
fr="17%">
<stop offset="0%" stop-color="fuchsia" />
<stop offset="100%" stop-color="orange" />
</radialGradient>
</defs>
<rect fill="url(#RadialPadGradient)" x="10" y="10" width="100" height="100" />
<rect
fill="url(#RadialReflectGradient)"
x="120"
y="10"
width="100"
height="100" />
<rect
fill="url(#RadialRepeatGradient)"
x="230"
y="10"
width="100"
height="100" />
</svg>
```
### Result
{{EmbedLiveSample('Examples_of_spreadMethod_with_radial_gradients')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}