简体   繁体   English

SVG viewBox="0 0 100 100" 不会将我的路径缩放到 100%?

[英]SVG viewBox="0 0 100 100" wont scale my path to 100%?

I currently have an svg path that only shows about 50%.我目前有一个仅显示约 50% 的 svg 路径。 How can I get it to show 100%?我怎样才能让它显示100%? Here is my code:这是我的代码:

<div className="svgPathContainer">
   <svg width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="none">
     <path d="M82 88L0 0H123V170H0L82 88Z" fill="#F9B300" />
  </svg>
</div>

I have className="svgPath" set as:我将 className="svgPath" 设置为:

.svgPathContainer{ 
  width: 100%;
  height: 100%;
} 

Here is also an example of the svg only showing at 50%: https://codesandbox.io/s/svg-scaling-fff1q?file=/src/App.js:93-357这也是 svg 仅显示 50% 的示例: https://codesandbox.io/s/svg-scaling-fff1q?file=/src/App.js:93-357

The problem: Why wont the svg path scale to 100% of the.svgPathContainer?问题:为什么 svg 路径不能缩放到 .svgPathContainer 的 100%?

The viewBox is like a canvas size. viewBox类似于 canvas 大小。 So drawings outside of this view box will be clipped.因此,此视图框之外的图形将被剪裁。 Like css overflow: hidden.像 css 溢出:隐藏。 And your drawing has a size of width 123px and height 170px.您的绘图的宽度为 123 像素,高度为 170 像素。 So you have to change the view box to this value.因此,您必须将视图框更改为该值。 Check our some docs .检查我们的一些文档

If you want to keep the viewbox of 100 x 100 px, you need to change your drawing element size (path).如果要保持 100 x 100 像素的视图框,则需要更改绘图元素大小(路径)。

The view box has nothing to do with the scale.视图框与比例无关。 It's just the canvas size.这只是 canvas 尺寸。 A rect clip with width, height and offset (xywh) for the SVG elements inside.一个矩形剪辑,其中包含 SVG 元素的宽度、高度和偏移量 (xywh)。 And the SVG tag's width and height attributes are for scale the rendered image. SVG 标签的宽度和高度属性用于缩放渲染图像。

 <div className="svgPathContainer"> <svg width="100%" height="100%" viewbox="0 0 123 170" preserveAspectRatio="none"> <path d="M82 88L0 0H123V170H0L82 88Z" fill="#F9B300" /> </svg> </div>

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

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