我有一个 SVG,需要用渐变填充它,CSS 是由脚本添加的。如果你只使用单一的 RGB 颜色,那么一切都可以正常工作,但是使用渐变填充时,SVG 的结果却是白色背景。
脚本执行后的代码如下:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
id="Livello_1" x="0px" y="0px" viewBox="0 0 70 70"
style="enable-background:new 0 0 70 70;width: 50px; height: 50px;"
xml:space="preserve">
<defs>
<lineargradient id="grC29M" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(88,88,88);stop-opacity:1"></stop>
<stop offset="100%" style="stop-color:rgb(255,255,255);stop-opacity:1"></stop>
</lineargradient>
</defs>
<path class="st0" d="......" style="fill: url("#grC29M")">
</svg>
谢谢!
style="fill: url("#grC29M")">
改为style="fill: url('#grC29M')"/>
(区别在于引号和闭合斜杠)即可。 - Max Starkenburg