<gradient>
CSS
data type
is a special type of
<image>
that consists of a progressive transition between two or more colors.
A CSS gradient has no intrinsic dimensions ; i.e., it has no natural or preferred size, nor a preferred ratio. Its concrete size will match the size of the element to which it applies.
<gradient>
data type is defined with one of the function types listed below.
Linear gradients transition colors progressively along an imaginary line. They are generated with the
linear-gradient()
函数。
Radial gradients transition colors progressively from a center point (origin). They are generated with the
radial-gradient()
函数。
Repeating gradients duplicate a gradient as much as necessary to fill a given area. They are generated with the
repeating-linear-gradient()
and
repeating-radial-gradient()
函数。
Conic gradients transition colors progressively
around a
circle
. They are generated with the
conic-gradient()
函数。
As with any interpolation involving colors, gradients are calculated in the alpha-premultiplied color space. This prevents unexpected shades of gray from appearing when both the color and the opacity are changing. (Be aware that older browsers may not use this behavior when using the transparent keyword .)
A simple linear gradient.
<div class="linear-gradient">Linear gradient</div>
div {
width: 240px;
height: 80px;
}
.linear-gradient {
background: linear-gradient(to right,
red, orange, yellow, green, blue, indigo, violet);
}
A simple radial gradient.
<div class="radial-gradient">Radial gradient</div>
div {
width: 240px;
height: 80px;
}
.radial-gradient {
background: radial-gradient(red, yellow, rgb(30, 144, 255));
}
Simple repeating linear and radial gradient examples.
<div class="linear-repeat">Repeating linear gradient</div> <br> <div class="radial-repeat">Repeating radial gradient</div>
div {
width: 240px;
height: 80px;
}
.linear-repeat {
background: repeating-linear-gradient(to top left,
lightpink, lightpink 5px, white 5px, white 10px);
}
.radial-repeat {
background: repeating-radial-gradient(powderblue, powderblue 8px, white 8px, white 16px);
}
A simple conic gradient example. Note that this isn't supported widely across browser as of yet.
<div class="conic-gradient">Conic gradient</div>
div {
width: 200px;
height: 200px;
}
.conic-gradient {
background: conic-gradient(lightpink, white, powderblue);
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Images Module Level 4
The definition of '<gradient>' in that specification. |
工作草案 | Adds conic-gradient |
|
CSS Images Module Level 3
The definition of '<gradient>' in that specification. |
候选推荐 | 初始定义。 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
<gradient>
|
Chrome 完整支持 26 |
Edge
完整支持
12
Prefixed
|
Firefox
完整支持
3.6
注意事项
|
IE
完整支持
10
Prefixed
|
Opera
完整支持
12.1
|
Safari 完整支持 6.1 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 26 |
Firefox Android
完整支持
4
注意事项
|
Opera Android
完整支持
12.1
|
Safari iOS 完整支持 7 | Samsung Internet Android 完整支持 1.5 |
conic-gradient()
|
Chrome
完整支持
69
|
Edge 完整支持 79 |
Firefox
完整支持
83
|
IE 不支持 No |
Opera
完整支持
56
|
Safari 完整支持 12.1 | WebView Android 完整支持 69 |
Chrome Android
完整支持
69
|
Firefox Android
完整支持
83
|
Opera Android
完整支持
48
|
Safari iOS 完整支持 12.2 | Samsung Internet Android 完整支持 10.0 |
linear-gradient()
|
Chrome 完整支持 26 | Edge 完整支持 12 |
Firefox
完整支持
16
注意事项
|
IE
完整支持
10
注意事项
|
Opera
完整支持
12.1
|
Safari
完整支持
6.1
|
WebView Android 完整支持 ≤37 | Chrome Android 完整支持 26 |
Firefox Android
完整支持
16
注意事项
|
Opera Android
完整支持
12.1
|
Safari iOS
完整支持
6.1
|
Samsung Internet Android 完整支持 1.5 |
radial-gradient()
|
Chrome 完整支持 26 | Edge 完整支持 12 |
Firefox
完整支持
16
注意事项
|
IE
完整支持
10
注意事项
|
Opera
完整支持
12.1
|
Safari
完整支持
6.1
|
WebView Android 完整支持 ≤37 | Chrome Android 完整支持 26 |
Firefox Android
完整支持
16
注意事项
|
Opera Android
完整支持
12.1
|
Safari iOS
完整支持
6.1
|
Samsung Internet Android 完整支持 1.5 |
repeating-conic-gradient()
|
Chrome
完整支持
69
|
Edge 完整支持 79 | Firefox 不支持 No | IE 不支持 No |
Opera
完整支持
56
|
Safari 完整支持 12.1 | WebView Android 完整支持 69 |
Chrome Android
完整支持
69
|
Firefox Android 不支持 No |
Opera Android
完整支持
48
|
Safari iOS 完整支持 12.2 | Samsung Internet Android 完整支持 10.0 |
repeating-linear-gradient()
|
Chrome 完整支持 26 | Edge 完整支持 12 |
Firefox
完整支持
16
注意事项
|
IE
完整支持
10
注意事项
|
Opera
完整支持
12.1
|
Safari
完整支持
6.1
|
WebView Android 完整支持 ≤37 | Chrome Android 完整支持 26 |
Firefox Android
完整支持
16
注意事项
|
Opera Android
完整支持
12.1
|
Safari iOS
完整支持
6.1
|
Samsung Internet Android 完整支持 1.5 |
repeating-radial-gradient()
|
Chrome 完整支持 26 | Edge 完整支持 12 |
Firefox
完整支持
16
注意事项
|
IE 完整支持 10 |
Opera
完整支持
12.1
|
Safari
完整支持
6.1
|
WebView Android 完整支持 4.4 | Chrome Android 完整支持 26 |
Firefox Android
完整支持
16
注意事项
|
Opera Android
完整支持
12.1
|
Safari iOS
完整支持
7
|
Samsung Internet Android 完整支持 1.5 |
完整支持
不支持
见实现注意事项。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
linear-gradient()
,
radial-gradient()
,
repeating-linear-gradient()
,
repeating-radial-gradient()
,
conic-gradient()
<angle-percentage>
<angle>
<basic-shape>
<blend-mode>
<custom-ident>
<dimension>
<frequency-percentage>
<frequency>
<gradient>
<image>
<integer>
<length-percentage>
<length>
<number>
<percentage>
<ratio>
<resolution>
<shape>
<string>
<time-percentage>
<time>
<transform-function>
<url>
color
flex
ident
image-orientation
image-rendering
object-fit
object-position
position