0

How to get a background in CSS to stretch or scale to fill its container size?

I am doing as below

body
{ 
    background: url(http://p1.pichost.me/i/40/1639647.jpg) no-repeat fixed; 
    background-size: 100%;
    margin:0;
}

Whats wrong in this code ?

Abhishek T.
  • 1,133
  • 1
  • 17
  • 33

3 Answers3

0

Try This to reset CSS:

* {
     margin:0;
     padding:0;
     border:0;
}

body {
       background: url(http://p1.pichost.me/i/40/1639647.jpg) no-repeat fixed;
       background-size: cover;
       -webkit-background-size: cover;
       -moz-background-size: cover;
       -o-background-size: cover;
     }
-2

Simply u can do this...

body {  
background: url(http://p1.pichost.me/i/40/1639647.jpg) no-repeat;
background-size: 100%;

}

-2

It looks like your code is working. Just note that when you apply a fixed background position, you take the image out the dom pretty much as if it were a fixed image, so if you do:

background: url(http://p1.pichost.me/i/40/1639647.jpg) no-repeat top left;
background-size: cover;

It should work as you hope. I came across this too, may be of help: CSS background-size: cover + background-attachment: fixed clipping background images

Community
  • 1
  • 1
AshboDev
  • 370
  • 2
  • 10
  • No idea why this was voted down. It's a valid answer, and fills the container size, in CSS, which is what the OP asked: How to get a background in CSS to stretch or scale to fill its container size? – AshboDev Jul 27 '16 at 11:48