color-interpolation CSS property
Baseline
Weitgehend verfügbar
*
Diese Funktion ist gut etabliert und funktioniert auf vielen Geräten und in vielen Browserversionen. Sie ist seit Januar 2020 browserübergreifend verfügbar.
* Einige Teile dieser Funktion werden möglicherweise unterschiedlich gut unterstützt.
Die CSS-Eigenschaft color-interpolation wird in SVG verwendet, um festzulegen, welcher Farbraum für die SVG-Elemente <linearGradient> und <radialGradient> verwendet wird.
Syntax
/* Keyword values */
color-interpolation: auto;
color-interpolation: sRGB;
color-interpolation: linearRGB;
Werte
Diese Eigenschaft wird mit einem der folgenden Schlüsselwortwerte angegeben:
auto-
Gibt an, dass der User Agent für die Farbinterpolation entweder den Farbraum
sRGBoderlinearRGBwählen kann. Diese Option bedeutet, dass keine Farbinterpolation in einem bestimmten Farbraum erforderlich ist. sRGB-
Gibt an, dass die Farbinterpolation im sRGB-Farbraum erfolgen soll. Wenn keine
color-interpolation-Eigenschaft festgelegt ist, gilt dieser Anfangswert. linearRGB-
Gibt an, dass die Farbinterpolation im linearisierten RGB-Farbraum erfolgen soll, wie in der sRGB-Spezifikation beschrieben.
Formale Definition
| Anfangswert | sRGB |
|---|---|
| Anwendbar auf | Container elements, graphics elements, gradient elements, <use>, and <animate> in <svg> |
| Vererbt | Ja |
| Berechneter Wert | wie angegeben |
| Animationstyp | diskret |
Formale Syntax
color-interpolation =
auto |
sRGB |
linearRGB |
<color-interpolation-method>
<color-interpolation-method> =
in [ <rectangular-color-space> | <polar-color-space> <hue-interpolation-method>? | <custom-color-space> ]
<rectangular-color-space> =
srgb |
srgb-linear |
display-p3 |
display-p3-linear |
a98-rgb |
prophoto-rgb |
rec2020 |
lab |
oklab |
<xyz-space>
<polar-color-space> =
hsl |
hwb |
lch |
oklch
<hue-interpolation-method> =
[ shorter | longer | increasing | decreasing ] hue
<custom-color-space> =
<dashed-ident>
<xyz-space> =
xyz |
xyz-d50 |
xyz-d65
Beispiel
Im ersten SVG ist die Eigenschaft color-interpolation nicht für das Element <linearGradient> festgelegt. Daher wird für die Farbinterpolation standardmäßig sRGB verwendet.
Das zweite Beispiel zeigt die Farbinterpolation mit dem Wert linearRGB.
<svg width="450" height="70">
<title>Example of using the color-interpolation CSS Property</title>
<defs>
<linearGradient id="sRGB">
<stop offset="0%" stop-color="white" />
<stop offset="25%" stop-color="blue" />
<stop offset="50%" stop-color="white" />
<stop offset="75%" stop-color="red" />
<stop offset="100%" stop-color="white" />
</linearGradient>
</defs>
<rect x="0" y="0" width="400" height="40" fill="url(#sRGB)" stroke="black" />
<text x="0" y="60" font-family="courier" font-size="16">
no color-interpolation (CSS property)
</text>
</svg>
<svg width="450" height="70">
<title>Example of using the color-interpolation CSS Property</title>
<defs>
<linearGradient id="linearRGB">
<stop offset="0%" stop-color="white" />
<stop offset="25%" stop-color="blue" />
<stop offset="50%" stop-color="white" />
<stop offset="75%" stop-color="red" />
<stop offset="100%" stop-color="white" />
</linearGradient>
</defs>
<rect
x="0"
y="0"
width="400"
height="40"
fill="url(#linearRGB)"
stroke="black" />
<text x="0" y="60" font-family="courier" font-size="16">
color-interpolation: linearRGB; (CSS property)
</text>
</svg>
svg {
display: block;
}
#linearRGB {
color-interpolation: linearRGB;
}
Spezifikationen
| Spezifikation |
|---|
| Scalable Vector Graphics (SVG) 2> # ColorInterpolationProperty> |
Browser-Kompatibilität
Siehe auch
<linearGradient><radialGradient>- SVG-Attribut
color-interpolation