简体   繁体   English

什么是SVG中的笔画和笔画宽度以及它在HTML中的呈现方式?

[英]what is stroke and stroke width in SVG and how is it rendered in the HTML?

<svg width="400" height="400" style="background-color:green">

   <circle cx="200" cy="200" r="50" stroke="red" stroke-width="5" fill="yellow"></circle></svg>

<svg width="400" height="400" style="background-color:green">

   <circle cx="200" cy="200" r="50" stroke="red" stroke-width="50" fill="yellow"></circle></svg>


<svg width="400" height="400" style="background-color:green">

   <circle cx="200" cy="200" r="50" stroke="red" stroke-width="100" fill="yellow"></circle></svg>


<svg width="400" height="400" style="background-color:green">

   <circle cx="200" cy="200" r="50" stroke="red" stroke-width="150" fill="yellow"></circle></svg>

中风宽度5 中风宽度50 行程宽度为100 行程宽度150

I've just started learning about SVGs and I am little confused about stroke and stroke width, and how they are rendered. 我刚刚开始学习SVG,我对笔画和笔画宽度以及如何渲染它们感到困惑。 In the developer tools, it looks strange whenever I increase the stroke width, the circle holding area increases but the dimensions are 100x100 always. 在开发人员工具中,每当我增加笔划宽度时它看起来都很奇怪,圆圈保持区域增加但尺寸总是100x100。 I want to know if the stroke width is being added to the radius or am I confused on its rendering. 我想知道是否将笔划宽度添加到半径中,或者我对其渲染感到困惑。 Someone need to explain the concept behind the svgs or direct me to some pages so that i can learn deep 有人需要解释svgs背后的概念或者将我引导到某些页面以便我可以深入学习

SVG stroke Property SVG中风属性

  • The stroke property defines the color of a line, text or outline of an element stroke属性定义元素的线条,文本或轮廓的颜色

SVG stroke-width Property SVG stroke-width属性

  • The stroke-width property defines the thickness of a line, text or outline of an element stroke-width属性定义元素的线条,文本或轮廓的粗细

Check this w3schools article for svg properties 查看这篇w3schools 文章了解svg属性

SVG is XML based, which means that every element is available within the SVG DOM. SVG是基于XML的,这意味着SVG DOM中的每个元素都可用。 You can attach JavaScript event handlers for an element. 您可以为元素附加JavaScript事件处理程序。

In SVG, each drawn shape is remembered as an object. 在SVG中,每个绘制的形状都被记住为一个对象。 If attributes of an SVG object are changed, the browser can automatically re-render the shape. 如果更改了SVG对象的属性,则浏览器可以自动重新渲染形状。

That problem that is showing to you is because the maximum stroke-width that you can apply to a circle with the radius 50px is 100px so it's a simple math. 向您显示的问题是,您可以应用于半径为50px的圆的最大笔触宽度为100px,因此这是一个简单的数学运算。 Your max stroke-width for r=50px is 2*r so it's 100px . r=50px最大行程宽度为2*r因此它是100px

When you add stroke-width = 150 it means that the stroke-width radius need to be bigger to hande that. 当你添加stroke-width = 150时,这意味着行程宽度半径需要更大才能得到它。 Chrome shows the circle as 100x100 and that's true the circle radius doesn't change only the stroke radius changes. Chrome将圆圈显示为100x100 ,圆形半径不会仅改变笔划半径的变化。

To prove that just change your stroke-width to 500px and you will clearly see how this is working and you will understand this. 要证明只需将笔划宽度更改为500px ,您就会清楚地看到它是如何工作的,您将理解这一点。

This is also known as bug so you have this open issue in this link 这也称为bug,因此您在此链接中有这个未解决的问题

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

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