Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS background image to fit height, width should auto-scale in proportion

Tags:

css

I want background image fit with the height of the div, there's a way to do that? background-size:cover; fit only with the width and height autoscale (I need the opposite effect). Thanks.

like image 544
tanzio Avatar asked Nov 20 '13 10:11

tanzio


People also ask

How do I make the background image resize automatically in CSS?

Use background-size property to cover the entire viewport The CSS background-size property can have the value of cover . The cover value tells the browser to automatically and proportionally scale the background image's width and height so that they are always equal to, or greater than, the viewport's width/height.

How do I stretch a background image in CSS to fit the screen?

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.

What does background-size Auto do?

If the background-size is auto or auto auto :If the image has both horizontal and vertical intrinsic dimensions, it's rendered at that size. If the image has no intrinsic dimensions and has no intrinsic proportions, it's rendered at the size of the background positioning area.


1 Answers

I know this is an old answer but for others searching for this; in your CSS try:

background-size: auto 100%; 
like image 71
Langlois.dev Avatar answered Oct 07 '22 01:10

Langlois.dev