问题描述
我有以下代码:
<span>
<svg height="32" version="1.1" width="32" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative; left: -0.0166626px; top: -0.983337px;">
<desc></desc>
<defs/>
<path style="" fill="#333333" stroke="none" d="M15.985,5.972C8.422,5.972,2.289999999999999,10.049,2.289999999999999,15.078C2.289999999999999,17.955,4.302999999999999...............1,27.68,22.274Z"/>
</svg>
</span>
可以使用CSS或其他方法更改SVG路径的填充颜色,它在path标签内?
Is it possible to change the fill color of the SVG path with CSS or some other means without actually changing it inside the path tag?
推荐答案
是的,您可以将CSS应用于SVG,但您需要匹配元素,当样式html时。如果您只想将它应用于所有SVG路径,您可以使用,例如:
Yes, you can apply CSS to SVG, but you need to match the element, just as when styling HTML. If you just want to apply it to all SVG paths, you could use, for example:
path {
fill: blue;
}
$ b 属性,至少在我测试的WebKit和基于Gecko的浏览器。当然,如果你写,< path style =fill:green>
那么将覆盖外部CSS。
External CSS appears to override the path's fill
attribute, at least in WebKit and Gecko-based browsers I tested. Of course, if you write, say, <path style="fill: green">
then that will override external CSS as well.
这篇关于我可以用CSS更改svg路径的填充颜色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!