I am trying to figure out how to stretch a background image vertically. I am using CSS3 with 3 images in the following way:
background-image: url("left.png"), url("right.png"), url("center.png") background-repeat: no-repeat, no-repeat, repeat-x background-position: top left, top right, top
Now I want to stretch these images vertically to that they extend all the way to the bottom. Is there a way to do this?
If I do background-size: 100%, it sets both width and height to a 100%. This was pretty handy. In my case, I set "background-size: 960px 100%;" to get the desired effect.
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.
Syntax: background-size: auto|length|cover|contain|initial|inherit; cover: This property value is used to stretch the background-image in x and y direction and cover the whole area. length: This property value is used to scale the background-image.
I'm late to the party here, but this is what worked for me:
background-size: auto 100%;
This will fit the image vertically and let the width do whatever it needs to do (i think it repeats by default). You can also set:
background-repeat: no-repeat;
for it to not repeat the image in the horizontal direction.
Try:
background-size: 100% 100%;
first 100%
is for the width and the second for the height. In your case you need the second set to 100%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With