使用CSS更改svg图像的颜色 [英] Changing the color of an svg image using CSS

查看:1100
本文介绍了使用CSS更改svg图像的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的html文件中有以下svg图片:

I have the following svg image in my html file:

<img class="svg" src="my-image-link.svg">

现在,我正尝试使用此CSS代码更改颜色:

Now, I am trying to change the color using this css code:

.svg path {
    fill: black;
}

然而,没有任何变化。使用css改变svg图像路径颜色的正确方法是什么?感谢!

However, nothing changes. What is the correct way to change the color of an svg image's path using css? Thanks!

推荐答案

您必须使用内联SVG,其中路径元素位于HTML内部,而不是链接到外部SVG。

You have to use an inline SVG, where the path element is inside the HTML, as opposed to linking to an external SVG.

示例: https:// jsfiddle。 net / fznuckb0 / 1 /

Example: https://jsfiddle.net/fznuckb0/1/

.path-name {
    fill: tomato;
    fill-rule: evenodd;
}

这篇关于使用CSS更改svg图像的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆