I'm trying to get my background image to stretch across the entire page, but so far i have this:
This is the picture i want stretched across the browser window:
My external CSS contains the code below:
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("mybackground.jpg")}
Can anyone tell me how I can edit the CSS file to fix my problem?
You can use:
However please bear in mind which browsers this supports. For example, this won't work in IE8 and below.
You need to make this an
<img>
tag, with a lowz-index
, withposition: fixed
and then for the<img>
tag, useheight: 100%; width: auto
or the opposite.This method is cross-compatible for all browsers.
Have you tried using
Change 10 to the width and height of the body
You can also do
Another option would also include:
Background size will do the trick:
Check this out for more info: http://css-tricks.com/perfect-full-page-background-image/
Use
background-size: cover
. Note its browser support.MDN documentation.