admin管理员组文章数量:1429618
I'm trying to figure out this, but having a lot of trouble:
<div class="wrapper">
<svg width="100%" height="100%" viewbox="0 0 100 100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>
</div>
How can I make it so that the viewbox coordinates stretch 100% in height & width, following the viewport coordinates of the svg element?
P.S. The wrapper is 100% wide and has a set height.
I'm trying to figure out this, but having a lot of trouble:
<div class="wrapper">
<svg width="100%" height="100%" viewbox="0 0 100 100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>
</div>
How can I make it so that the viewbox coordinates stretch 100% in height & width, following the viewport coordinates of the svg element?
P.S. The wrapper is 100% wide and has a set height.
Share Improve this question asked May 1, 2018 at 17:45 Tamara JovicTamara Jovic 2391 gold badge3 silver badges4 bronze badges1 Answer
Reset to default 3Just remove the 'height' and 'width' attributes from your SVG element.
<div class="wrapper">
<svg viewbox="0 0 100 100">
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>
</div>
https://jsfiddle/mhcp4qpy/
SVGs are a bit odd because they scale differently than most img elements. Most ppl 'overthink' it.
If you'd like the height to also fill the container 100% and never overflow, you can change the 'preserveAspectRatio' attribute on the SVG to make it so that it will distort beyond its original aspect ratio.
https://developer.mozilla/en-US/docs/Web/SVG/Attribute/preserveAspectRatio
本文标签: javascriptHow to make an SVG viewbox wide as its containerStack Overflow
版权声明:本文标题:javascript - How to make an SVG viewbox wide as its container? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745548969a2662840.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论