Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically stretch background image

Tags:

css

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?

like image 938
user1539137 Avatar asked Oct 02 '12 16:10

user1539137


People also ask

How do I stretch a background image in CSS vertically?

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.

How do I stretch a background image?

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 stretch a background image horizontally?

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.


2 Answers

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.

like image 171
mr_mariusz Avatar answered Sep 24 '22 02:09

mr_mariusz


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%

like image 40
Erind Dollaku Avatar answered Sep 21 '22 02:09

Erind Dollaku