如何为 svg 元素路径提供背景颜色?
How to give background color to svg element path?
我已经将图像转换为 svg 并获得如下所示的路径向量
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="122.000000pt" height="98.000000pt" viewBox="0 0 122.000000 98.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.14, written by Peter Selinger 2001-2017
</metadata>
<g transform="translate(0.000000,98.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M93 873 c-7 -3 -6 -653 0 -660 5 -4 889 -185 892 -181 1 1 35 69 74
151 l71 147 0 273 0 272 -515 0 c-283 0 -518 -1 -522 -2z m1007 -284 l0 -251
-66 -139 c-59 -122 -70 -138 -88 -134 -12 3 -106 23 -211 46 -104 22 -219 47
-255 54 -36 8 -85 21 -109 30 -24 8 -56 15 -70 15 -15 0 -49 7 -75 16 -26 9
-58 14 -71 12 -15 -3 -26 0 -29 9 -4 8 -6 145 -6 304 l0 289 490 0 490 0 0
-251z" style="fill:green;background-color:red"/>
</g>
</svg>
我想要的是用任何颜色填充路径,但是当我使用填充时它只改变边框的颜色而不是完整路径节点的内部颜色。
我试过了
style="fill:green;background-color:red"
但只改变边框而不是内部不工作?
这是 jsfiddle link Link to example 任何主体都可以转换并用颜色填充路径吗?
问题是您的 SVG
没有 "inner"。您的 SVG
实际上就是您所说的边框。你不能为里面的东西设置颜色,因为它不是你的 SVG
.
的一部分
您的图片中指定了 "hole"。这是代码中以 m1007
开头并以 -251z
结尾的路径 - 由于规范:"The M indicates a moveto, ... and the z indicates a closepath)".. 如果删除该部分,你将拥有整个形状 w/o里面的缝隙。
我已经将图像转换为 svg 并获得如下所示的路径向量
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="122.000000pt" height="98.000000pt" viewBox="0 0 122.000000 98.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.14, written by Peter Selinger 2001-2017
</metadata>
<g transform="translate(0.000000,98.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M93 873 c-7 -3 -6 -653 0 -660 5 -4 889 -185 892 -181 1 1 35 69 74
151 l71 147 0 273 0 272 -515 0 c-283 0 -518 -1 -522 -2z m1007 -284 l0 -251
-66 -139 c-59 -122 -70 -138 -88 -134 -12 3 -106 23 -211 46 -104 22 -219 47
-255 54 -36 8 -85 21 -109 30 -24 8 -56 15 -70 15 -15 0 -49 7 -75 16 -26 9
-58 14 -71 12 -15 -3 -26 0 -29 9 -4 8 -6 145 -6 304 l0 289 490 0 490 0 0
-251z" style="fill:green;background-color:red"/>
</g>
</svg>
我想要的是用任何颜色填充路径,但是当我使用填充时它只改变边框的颜色而不是完整路径节点的内部颜色。 我试过了
style="fill:green;background-color:red"
但只改变边框而不是内部不工作? 这是 jsfiddle link Link to example 任何主体都可以转换并用颜色填充路径吗?
问题是您的 SVG
没有 "inner"。您的 SVG
实际上就是您所说的边框。你不能为里面的东西设置颜色,因为它不是你的 SVG
.
您的图片中指定了 "hole"。这是代码中以 m1007
开头并以 -251z
结尾的路径 - 由于规范:"The M indicates a moveto, ... and the z indicates a closepath)".. 如果删除该部分,你将拥有整个形状 w/o里面的缝隙。