小编Jam*_*nes的帖子

如何继承SVG中的笔触颜色?(不是填充,而是描边颜色)

我有一个 .SVG 在那里我用<img src="/image/arrow.svg" alt="Arrow">. 一切都很好,但我想为我的 SVG 动态设置不同的笔触颜色(不是填充颜色...),例如<img ... style="color:red">. 我读到我可以在我的路径上使用 fill="currentColor" ,但是我该怎么做我的笔触颜色?

我的SVG文件:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" height="100" width="100">
    <path d="M20 10 H90 V80" fill="transparent" stroke="currentColor" stroke-width="20" stroke-linecap="round"></path>
    <path d="M10 90 L100 0" fill="transparent" stroke="currentColor" stroke-width="20" stroke-linecap="round"></path>
</svg>
Run Code Online (Sandbox Code Playgroud)

我的html:

<img src="/image/arrow.svg" alt="Arrow" style="color:red">
Run Code Online (Sandbox Code Playgroud)

svg colors stroke

5
推荐指数
1
解决办法
2412
查看次数

标签 统计

colors ×1

stroke ×1

svg ×1