【发布时间】:2018-06-09 23:08:47
【问题描述】:
我在 svg 中有以下图标,其中包含一个矩形。 我需要用红色着色(现在它们是白色的)。 使用我当前的 CSS 解决方案,我无法获得想要的结果。 知道如何解决吗?
注意这个问题与其他问题不同,因为它仅与 rect 相关,而不与路径相关。
.icon rect {
fill: red;
}
html {
background-color: gray;
}
<div class="icon">
<svg width="50%" height="50%" viewBox="0 0 16 20" version="1.1" xmlns="http://www.w3.org/2000/svg">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(-28.000000, -26.000000)" stroke-width="2" stroke="#FFFFFF">
<rect x="43" y="27" width="1" height="18"></rect>
<rect x="29" y="27" width="1" height="18"></rect>
</g>
</g>
</svg>
</div>
【问题讨论】:
-
矩形元素没有可见的填充,因为 1/2 的笔触宽度 >= 宽度,所以您看到的只是笔触和笔触颜色。