简体   繁体   English

HTML SVG笔触边缘变宽

[英]HTML SVG Stroke wider at edges

I have created this scalable vector graphic. 我创建了此可缩放的矢量图形。

 <svg width="150" height="90" style="stroke: black;"> <rect width="40" height="90" style="fill:white;"></rect> <polygon points="40,0 40,90 150,90 100,45 150,0" style="fill:blue;"/> </svg> 

I am aiming for the left hand side but the result returns the right hand side. 我的目标是左侧,但结果返回右侧。

iamge

As you can see the vertical edges have wider strokes than the horizontal. 如您所见,垂直边缘的笔触比水平边缘的笔触宽。 Is this a defect of svg? 这是svg的缺陷吗? Is there a way a can mitigate it to achieve a more consistent stroke. 有没有一种方法可以减轻它以获得更一致的笔画。

The edges of your shape consincide with the ouside boundary of your SVG. 形状的边缘与SVG的贴边边界重合。 Strokes are drawn so that half their width is on either side of the line. 绘制描边,使其宽度的一半位于线条的两侧。

So whats happening is that half of the top, left and bottom lines are cut off because they are outside of the SVG. 因此,发生的情况是顶部,左侧和底部的一半线被切除,因为它们在SVG之外。

Some solutions would be: 一些解决方案是:

  1. Move your lines inside the SVG by half the stroke width. 将线在SVG内移动笔划宽度的一半。
  2. Add a viewBox that is half the stroke width bigger than your shape. 添加一个viewBox ,该viewBox的笔触宽度比您的形状大一半。 This will have the effect of scaling down your shape so that all the stroke is drawn. 这将具有缩小形状的效果,以便绘制所有笔触。
  3. Add overflow="visible" to your SVG so that that the parts of your shape that are outside the SVG are drawn, and not clipped (as suggested by @enxaneta) 在您的SVG中添加overflow="visible" ,以便绘制而不是剪切掉SVG之外的形状部分(如@enxaneta所建议)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM