简体   繁体   English

如何通过css更改svg的样式颜色

[英]How to change the style color of svg via css

I am currently building my first website and wanted to implement some svg's.我目前正在构建我的第一个网站,并希望实现一些 svg。 I downloaded some and changed them up a bit with inkscape.我下载了一些并用inkscape对其进行了一些更改。 The color for the svg is saved like this: svg 的颜色保存如下:

<path
     d="M 44.00,166.00 ..."
     style="fill:#000000;" />

is there a way to change the color with css.有没有办法用css改变颜色。 For example if i hover over it it changes the color?例如,如果我将鼠标悬停在它上面它会改变颜色?

Thanks for any help in advance感谢您提前提供任何帮助

You probably have it surrounded with <svg> so it would be something like:你可能用<svg>包围它,所以它是这样的:

<svg class='icon' [...]>
   <path d="M 44.00,166.00 ..."
     style="fill:#000000;" />
</svg>

Then you can change it with:然后你可以改变它:

.icon path {
  fill: red;
}

Notice that it's not the SVG that gets fill but path inside the SVG element.请注意, fill的不是 SVG,而是 SVG 元素内的路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM