如何更改 svg 元素的颜色? [英] How to change the color of an svg element?

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

问题描述

我想使用这种技术并更改 SVG 颜色,但到目前为止我还没有不能这样做.我把它放在 CSS 中,但无论如何我的图像总是黑色的.

I want to use this technique and change the SVG color, but so far I haven't been able to do so. I put this in the CSS, but my image is always black, no matter what.

我的代码:

.change-my-color {
  fill: green;
}

<svg>
    <image class="change-my-color" xlink:href="https://svgur.com/i/AFM.svg" width="96" height="96" src="ppngfallback.png" />
</svg>

推荐答案

您不能以这种方式更改图像的颜色.如果您将 SVG 作为图像加载,则无法在浏览器中使用 CSS 或 Javascript 更改其显示方式.

You can't change the color of an image that way. If you load SVG as an image, you can't change how it is displayed using CSS or Javascript in the browser.

如果你想改变你的 SVG 图像,你必须使用