Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

background-size:100% 100%; doesn't work properly in Chrome

I'm using an svg image as a background. I'm trying to use CSS3's background-size: 100% 100%; but it doesn't seem to work, even in browsers which should support it (like Chrome).

If you look at this site you'll see the #special-post article (to the right/below the food image) with a red banner-looking background. Notice that as you shrink the window down, the height of the background image drops to retain it's proportions, rather then stretching, as I would like.

EDIT: I checked this on FireFox and it works correctly... so this appears to be a webkit issue.

EDIT: I checked this on Safari and it works! So it looks like my problem is specific to Chrome.

(PS: I'm familiar with this alternative solution, using an img tag, but I'd rather not use it.)

like image 628
emersonthis Avatar asked Feb 17 '12 19:02

emersonthis


People also ask

How do I make my background-size responsive?

Here's how to create responsive background images with CSS: Use the background-size property to encompass the viewport. Give this property a cover value that will tell a browser to scale the background image's heights and width so that they always remain equal to or greater than the height/width of the device viewport.

How do I stretch a background image to the whole page?

When you work with background images, you may want an image to stretch to fit the page despite the wide range of devices and screen sizes. The best way to stretch an image to fit the background of an element is to use the CSS3 property, for background-size, and set it equal to cover.

How do I automatically resize a background image?

There are four different syntaxes you can use with this property: the keyword syntax ("auto", "cover" and "contain"), the one-value syntax (sets the width of the image (height becomes "auto"), the two-value syntax (first value: width of the image, second value: height), and the multiple background syntax (separated ...

Does Chrome support background?

As of March 2016, Background sync is available in Chrome from version 49 and above.


1 Answers

Here's a workaround:

Open your .svg file, find the <svg> tag at the beginning and add the following property inside it:

preserveAspectRatio="none" 

Source: http://www.yootheme.com/support/question/6801?order=modified

like image 168
dogcat Avatar answered Nov 08 '22 10:11

dogcat