Html 外部样式表中带有fill:url(#id)样式的Firefox SVG已损坏,内联样式也可以
仅在Firefox中,如果我尝试为svg路径提供模式引用,如:Html 外部样式表中带有fill:url(#id)样式的Firefox SVG已损坏,内联样式也可以,html,firefox,svg,Html,Firefox,Svg,仅在Firefox中,如果我尝试为svg路径提供模式引用,如: <pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213"> <image x="0" y="0" width="213" height="122" xlink:href=""/> </pattern> <patte
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
路径{
填写:url(#ref);
}
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
在外部样式表中,它渲染为不可见。如果我以内联方式或在页面上的标记中执行,它就会工作
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
这是我的小提琴,这是我的代码转储,因为SO不允许我发布小提琴。
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
.slice:第n个子(6n+2)路径{
填充:url(#纹理1);
}
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
#texture1
是
+#texturel
的缩写。因此,在外部样式表中,texture1将指向样式表本身中的某些内容,这些内容在svg文件中找不到
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
Webkit总是犯这个错误,这会引起很多混乱。你应该发现Opera与Firefox的行为相匹配,IE也是如此
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
如果要在样式表中执行此操作,则必须使用绝对URL,例如URL()
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
这一点包含在本手册中。当我们使用css(外部和内部css)分配下面的代码时,您可以随时联系.SVG“fill:url(#…)”在Firefox中的行为异常
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
解决方案
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
提供内联样式,这可以通过两种方式完成。静态还是动态
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
.attr('fill', 'url(#gradient-id)')
动态方式
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
.attr('fill', 'url(#gradient-id)')
静态方式
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>
fill="url(#gradient-id)"
在静态中,您必须将其放入SVG Html中 那么如何在外部样式表中引用当前dom呢?这似乎与直觉相反,这就是CSS样式表的规则。我想他们并没有真正考虑SVG用例。我看到你们评论了很多围绕这个案例归档的firefox bug。。。我知道样式表规范说这就是你应该如何引用URL的,但你基本上是在强迫我在页面上内联任何svg样式。。。看起来Chrome/webkit的折衷方案是合乎逻辑的。或者至少给我一个选项,强制它也可以工作,用js替换css代码。
<pattern id="texture_base" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<image x="0" y="0" width="213" height="122" xlink:href=""/>
</pattern>
<pattern id="texture1" x="0" y="0" patternUnits="userSpaceOnUse" height="122" width="213">
<rect fill='url(#color1)' stroke="none" x="0" y="0" width="213" height="122"/>
<rect fill='url(#texture_base)' x="0" y="0" width="213" height="122"/ />
</pattern>
</defs>
</svg>