这是一个示例代码,可以参考:
<svg width="100" height="100">
<defs>
<linearGradient id="gradient" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0%" stop-color="yellow" />
<stop offset="70%" stop-color="yellow" />
<stop offset="100%" stop-color="transparent" />
</linearGradient>
</defs>
<path d="M10 10 L90 10 L50 90 Z" fill="url(#gradient)" />
</svg>
其中,linearGradient
定义了一个线性渐变,stop
标签定义了渐变的颜色和位置。path
用 fill
属性引用了渐变。在 stop
中,offset
属性规定了渐变颜色的位置,例如 offset="70%"
表示从 70% 的位置开始变成透明。