Html 使用 CSS 更改 svg 图像的颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40343354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing the color of an svg image using CSS
提问by darkhorse
I have the following svg image in my html file:
我的 html 文件中有以下 svg 图像:
<img class="svg" src="my-image-link.svg">
Now, I am trying to change the color using this css code:
现在,我正在尝试使用此 css 代码更改颜色:
.svg path {
fill: black;
}
However, nothing changes. What is the correct way to change the color of an svg image's path using css? Thanks!
然而,什么都没有改变。使用 css 更改 svg 图像路径颜色的正确方法是什么?谢谢!
回答by FalcoB
回答by rorymorris89
You have to use an inline SVG, where the path element is inside the HTML, as opposed to linking to an external SVG.
您必须使用内联 SVG,其中路径元素位于 HTML 内部,而不是链接到外部 SVG。
Example: https://jsfiddle.net/fznuckb0/1/
示例:https: //jsfiddle.net/fznuckb0/1/
.path-name {
fill: tomato;
fill-rule: evenodd;
}