【发布时间】:2011-09-30 17:56:49
【问题描述】:
我可以在带有 defs-section 的 SVG 中使用线性渐变,例如:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="myLinearGradient1"
x1="0%" y1="0%"
x2="0%" y2="100%"
spreadMethod="pad">
<stop offset="0%" stop-color="#00cc00" stop-opacity="1"/>
<stop offset="100%" stop-color="#006600" stop-opacity="1"/>
</linearGradient>
</defs>
<rect x="0" y="0" width="100" height="100"
style="fill:url(#myLinearGradient1)" />
</svg>
我可以在没有 defs-section 的情况下使用线性渐变吗?我发现这样的事情:
<rect style="fill:lineargradient(foo)">
【问题讨论】:
-
我也在尝试在纯 CSS 中定义渐变,而不必在每个 SVG 文件中定义它。最重要的是没有
id标签,因为当 SVG 在页面上多次出现(例如图标)时,冲突的 id 不是唯一的,它不是有效的 HTML。到目前为止,我还没有找到解决方案...
标签: svg gradient linear-gradients