Autoscaling an SVG embedded in HTML on window resize

后端 未结 1 1247
庸人自扰
庸人自扰 2020-12-23 14:43

I would like to embed some SVG in an HTML page in a way such that is is automatically resized (using SVG, CSS, or JS) when the page is resized, while still preserving the or

1条回答
  •  梦毁少年i
    2020-12-23 15:07

    You need a viewBox-attribute on your SVG root element, which will define the overall size of the SVG-image:

    
    

    Now you can set the width OR height of the image via CSS and it will scale perfectly.

    0 讨论(0)
提交回复
热议问题