CSS background image to fit height, width should auto-scale in proportion
CssCss Problem Overview
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.
Css Solutions
Solution 1 - Css
I know this is an old answer but for others searching for this; in your CSS try:
background-size: auto 100%;
Solution 2 - Css
background-size: contain;
suits me
Solution 3 - Css
try
.something {
background: url(images/bg.jpg) no-repeat center center fixed;
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: -100;
}
Solution 4 - Css
body.bg {
background-size: cover;
background-repeat: no-repeat;
min-height: 100vh;
background: white url(../images/bg-404.jpg) center center no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
Try This
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
body.bg {
background-size: cover;
background-repeat: no-repeat;
min-height: 100vh;
background: white url(http://lorempixel.com/output/city-q-c-1920-1080-7.jpg) center center no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
<!-- language: lang-html -->
<body class="bg">
</body>
<!-- end snippet -->
Solution 5 - Css
I just had the same issue and this helped me:
html {
height: auto;
min-height: 100%;
background-size:cover;
}