Search code examples
csssvg

How to set svg width and svg height by percent?


I create a line with svg.but when I resize my browser the line created with svg not resized.

I try to set width the svg in percent but after doing that the line not appear. How I can set width of svg by percent??

<svg height="210" width="500">
  <line x1="380" y1="20" x2="230" y2="200" style="stroke: rgb(234, 243, 234); stroke-width: 5"></line>
</svg>

Solution

  • I solved my problem. I change my code to this and this is working:

    <svg style="width:100%;height:100%;">
      <line x1="100%" y1="0%" x2="0%" y2="100%" style="stroke: rgb(234, 243, 234);stroke-width: 5;"></line>
    </svg>