Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale SVG image without aspect ratio

Tags:

html

css

svg

Is it possible to fit the svg image to its full size without maintaining the aspect ratio? In the below example,

<img style="position: absolute; top: 12px; left: 31px; z-index: 1; width: 196px; height: 265px; " src="/media/images/logo.svg" />

enter image description here

The svg image is centered adding some transparent spaces along its sides. If I increase the size of the image, the svg image increases proportionally but does not take the entire space, instead the transparent space increases in size. Is there a way to allow the svg image to occupy the entire space?

Thanks and Regards,

Neha

like image 644
Neha Dangui Avatar asked May 08 '18 05:05

Neha Dangui


1 Answers

I solved the same problem with help of this article. The important part for you would be:

In order to prevent the uniform scaling of our SVG graphic we need to add the preserveAspectRatio attribute with the value of "none".

So open your SVG file in text editor and add attribute preserveAspectRatio="none" to <svg> tag. Like:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="none">
like image 198
Milan Švehla Avatar answered Sep 21 '22 05:09

Milan Švehla