css - Autoscaling an SVG embedded in HTML on window resize -


i embed svg in html page in way such is automatically resized (using svg, css, or js) when page resized, while still preserving original aspect ratio.

for example, using example w3schools:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">   <circle cx="100" cy="50" r="40" stroke="black"   stroke-width="2" fill="red"/> </svg> 

is possible set svg width = 5% of window width, , have height scaled proportionately?

i've tried couple things including preserveaspectratio="xminymin meet" , setting dimensions 100% within <div> container, haven't gotten working yet.

any suggestions?

you need viewbox-attribute on svg root element, define overall size of svg-image:

<svg version="1.1" viewbox="0 0 300 185"> 

now can set width or height of image via css , scale perfectly.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -