How to show full height background image?

CssImageBackground

Css Problem Overview


I have a photo type (not landscape) background image with 979px width by 1200px height. I would like to set it to float left and show 100% full image height fixed, without the need to scroll up/down (regardless of content length).

This is my CSS code, but it is not working:

img, media {
    max-width: 100%;
}

body {
	background-color: white;
	background-image: url('../images/bg-image.jpg');
	background-size: auto 100%;
	background-repeat: no-repeat;
	background-position: left top;
}

Css Solutions


Solution 1 - Css

You can do it with the code you have, you just need to ensure that html and body are set to 100% height.

Demo: http://jsfiddle.net/kevinPHPkevin/a7eGN/

html, body {
    height:100%;
} 

body {
    background-color: white;
    background-image: url('http://www.canvaz.com/portrait/charcoal-1.jpg');
    background-size: auto 100%;
    background-repeat: no-repeat;
    background-position: left top;
}

Solution 2 - Css

CSS can do that with background-size: cover;

But to be more detailed and support more browsers...

Use aspect ratio like this:

 aspectRatio      = $bg.width() / $bg.height();

FIDDLE

Solution 3 - Css

body{
    background-image: url("../images/shape/Online_Do`kon.svg");
    background-repeat: no-repeat;
    background-size: 100% 100%; 
    height: 100vh;
}

this will create fully responsive image and shows 100% of images height but don`t actually cover full screen height

Solution 4 - Css

 html, body {
    height:100%;
}

body { 
    background: url(images/bg.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

Solution 5 - Css

This worked for me (though it's for reactjs & tachyons used as inline CSS)

<div className="pa2 cf vh-100-ns" style={{backgroundImage: `url(${a6})`}}> 
........
</div>

This takes in css as height: 100vh

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhangeeView Question on Stackoverflow
Solution 1 - CssKevin LynchView Answer on Stackoverflow
Solution 2 - CssRiskbreakerView Answer on Stackoverflow
Solution 3 - CssAlijon JumanazarovView Answer on Stackoverflow
Solution 4 - CsshimView Answer on Stackoverflow
Solution 5 - CssmanzimView Answer on Stackoverflow