Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome - stretch background image without keeping ratio

I have the following code:

.container {
  width: 1rem;
  height: 2rem;
  background-image: url(https://dl.dropboxusercontent.com/u/1142760/static/svg/triangle.svg);
  background-size: 100% 100%;
  border: 1px solid black;
}
<div class="container"></div>

I expect the background image of the div to be stretched to the full width and height of said div.

Firefox behaves as expected:

the arrow is nicely stretched to the full width and height of the container, distorting the original image's aspect ratio

But Chrome appears to have a bug that makes it interpret background-size differently:

enter image description here

You can see the live result in this fiddle

Re-creating the background image would not be a solution, as the div in question is of variable height.

Is there a work-around for this Chrome bug?

like image 804
Kuba Orlik Avatar asked Jul 22 '15 07:07

Kuba Orlik


1 Answers

Maybe someone will find this post and not find the right answer. I found out that in my case, i had to add an attribute to my svg File:

<svg preserveAspectRatio="none" ... 
like image 100
Rory Avatar answered Sep 30 '22 08:09

Rory