Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css perfect full screen image background

I'm wondering which is the best solution for an background image to fit every screen, every browser. Also I've noticed that the majority of techniques crop the image a little bit. I know there are a lot of techniques to do this but I want to know which is the best in your opinion. Thanks!

like image 714
alexandru Avatar asked Aug 31 '11 15:08

alexandru


People also ask

How do I make a background image fit the whole screen CSS?

Fill the Entire Viewport with the background-size Property It is possible to set the CSS background-size property to cover. Using this value, the browser will automatically and proportionally scale the background image's width and height so that they are either equal to or greater than the view port's width and height.

How do I scale a background image in CSS?

You can use the CSS background-size: cover; to stretch and scale an image in the background with CSS only. This scales the image as large as possible in such a way that the background area is completely covered by the background image, while preserving its intrinsic aspect ratio.


1 Answers

This post from CSS-tricks.com covers different techniques for full screen background images and includes a fall-back for old versions of IE (I haven't tested the IE fix).

When I don't need to worry about supporting old browsers, I generally use the CSS3 method:

html { 
    background: url(http://lorempixum.com/1440/900/sports)
        no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}
like image 139
DuMaurier Avatar answered Sep 28 '22 04:09

DuMaurier