【问题标题】:Setting an SVG patterns color on usage在使用时设置 SVG 图案颜色
【发布时间】:2014-09-17 05:38:37
【问题描述】:

我有一个简单的孵化图案:

<defs>                                
  <pattern id="pattern1" patternUnits="userSpaceOnUse"
           x="0" y="0" width="10" height="10"
           >
    <line x1="0" y1="0" x2="10" y2="10" stroke="black" />
    <line x1="0" y1="-10" x2="20" y2="10" stroke="black" />
    <line x1="-10" y1="0" x2="10" y2="20" stroke="black" />
  </pattern>
</defs>                               

<rect fill="url(#pattern1)" stroke="black" 
      x="100" y="100" width="200" height="100"/>

<rect fill="url(#pattern1)" stroke="red" 
      x="100" y="300" width="200" height="100"/>

有没有办法在使用时设置图案中线条的颜色?例如,我想将第二个rect的颜色设置为红色。

【问题讨论】:

    标签: design-patterns svg colors


    【解决方案1】:

    如果您更新了图案中的颜色,它将影响两个矩形。如果您想在不同的矩形中使用不同的图案颜色,则必须使用不同的图案。

    【讨论】:

    • 谢谢。在那种情况下,我必须避免使用模式
    猜你喜欢
    • 2017-09-11
    • 2017-11-18
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 2017-01-04
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    相关资源
    最近更新 更多