我知道我们可以改变 fill
如果/当原始 SVG 添加到 HTML 页面时,使用 CSS 的 SVG 路径的颜色。
但是,我不知道是否可以更改 fill
如果在 <img>
中引用 SVG,则为颜色标签。 - 是否可以?如果是,怎么办?
示例:这 fill
示例不起作用,因为我在 img
中引用 svg标签。
<html>
...
<style>
#foo{
fill: #ccc;
}
</style>
<body>
<img id="foo" src="myicon.svg" />
</body>
</html>
最佳答案
您不能通过 CSS 影响源位于另一个文件中的 SVG 图像。 你只能影响文件本身或将 SVG 内嵌在 HTML 中,然后样式会起作用。
SVG 内联示例:
<!DOCTYPE html>
<html>
<body>
<style>
#foo{
fill: #ccc;
}
</style>
<svg id="foo" width="300" height="200">
<polygon points="100,10 40,180 190,60 10,60 160,180"
style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />
</svg>
</body>
</html>
关于css - 如何通过 CSS 更改 SVG 路径的填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23231907/