有一个圆圈,它有fill
和stroke
。但我发现fill
颜色与stroke
有一点重叠。当我对none
执行stroke
操作时,我失去了之前的圆半径,因为它释放了空间。
我原以为fill
和stroke
的行为与CSS中的background
和border
相同,但事实并非如此。我不能用相同的不透明度设置它们相同的颜色,因为fill
会与stroke
重叠,我会看到另一种颜色出现。
fill
和stroke
都设置为红色,具有相同的不透明度。
我该怎么做,这样fill
就停止在stroke
开始的地方(让fill
和stroke
具有相同的颜色和不透明度),并且我有没有任何边界的平面颜色?
发布于 2021-09-22 20:04:35
你正在寻找stroke-alignment
,尽管它是一个从未实现过的CSS特性--参见https://www.w3.org/TR/svg-strokes/#SpecifyingStrokeAlignment。
对于简单的几何体,可以通过复制结构并进行调整来实现这一点。
#c1 {
fill: red;
fill-opacity: 0.3;
stroke: none;
}
#c2 {
stroke: green;
stroke-opacity: 0.3;
fill: none;
}
<svg viewBox="0 0 40 40">
<circle id="c1" cx="20" cy="20" r="11.5" stroke-width="3"></circle>
<circle id="c2" cx="20" cy="20" r="13" stroke-width="3"></circle>
</svg>
或者通过改变元素的不透明度,而不是改变属性。
svg circle {
opacity: 0.3;
fill: red;
stroke: green;
}
<svg viewBox="0 0 40 40">
<circle cx="20" cy="20" r="13" stroke-width="3"></circle>
</svg>
https://stackoverflow.com/questions/69290489
复制相似问题