Solution 1 :

As commented by @Temani Afif for these purposes you need to use viewBox

Container parent dimensions must be specified in relative units vh, vw or as a percentage

.col-12 {
width:100%;
height:100%;
}
<div class="col-12" style="background-color:teal;">
                    <svg viewBox="0 0 500 500">
    
                        <polyline fill="none"
                                  stroke="#ced4da"
                                  stroke-width="2"
                                  points="
           00,120
           20,60
           40,80
           60,20
           80,80
           100,80
           120,60
           140,100
           160,90
           180,80
           200, 110
           220, 10
           240, 70
           260, 100
           280, 100
           300, 40
           320, 0
           340, 100
           360, 100
           380, 120
           400, 60
           420, 70
           440, 80
         " />
    
                    </svg>
    
            </div>

Problem :

I have a SVG polyline drawing in Javascript:

    <div class="col-12" style="background-color:teal;">
                    <svg>
    
                        <polyline fill="none"
                                  stroke="#ced4da"
                                  stroke-width="2"
                                  points="
           00,120
           20,60
           40,80
           60,20
           80,80
           100,80
           120,60
           140,100
           160,90
           180,80
           200, 110
           220, 10
           240, 70
           260, 100
           280, 100
           300, 40
           320, 0
           340, 100
           360, 100
           380, 120
           400, 60
           420, 70
           440, 80
         " />
    
                    </svg>
    
            </div>

But i want to make it responsive in such manner that it fits whatever container i put this into. (Col-8,10,12 etc.)

So far i tried to use width, transform: scale() and many other css attributes but none of them did do the trick.

How can i scale it according to parent, has to be responsive. Stretch factor and aspect ratio’s are out of concern, can be stretchered. Even the smallest idea counts. Thanks in advance.

Comments

Comment posted by developer.mozilla.org/en-US/docs/Web/SVG/Attribute/…

start by giving it a viewbox then check this

Comment posted by Skywarth

I believe this is exactly what i was looking for. Scales really well and quite responsive. Thanks, appreciated.

Comment posted by Alexandr_TT

@Skywarth If you want the line to cover the full width of the screen, add preserveAspectRatio=”none” Add an example?

By