--- title: linearGradient slug: Web/SVG/Element/linearGradient tags: - SVG - SVG渐变 - 元素 translation_of: Web/SVG/Element/linearGradient ---
linearGradient元素用来定义线性渐变,用于图形元素的填充或描边。
{{svginfo}}
<svg width="120" height="120" viewBox="0 0 120 120"
xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink" >
<defs>
<linearGradient id="MyGradient">
<stop offset="5%" stop-color="green"/>
<stop offset="95%" stop-color="gold"/>
</linearGradient>
</defs>
<rect fill="url(#MyGradient)"
x="10" y="10" width="100" height="100"/>
</svg>
{{EmbedLiveSample("Example", 120, 120, "https://mdn.mozillademos.org/files/10061/svg-lineargradient.png")}}
该元素实现了SVGLinearGradientElement接口。