Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css - how to stretch and auto-resize background image

Tags:

html

css

I'm trying to get my background image to stretch across the entire page, but so far i have this:

enter image description here

This is the picture i want stretched across the browser window:

enter image description here

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?

like image 768
user1283674 Avatar asked Jan 18 '14 21:01

user1283674


2 Answers

Another option would also include:

body{
   background-image:url("mybackground.jpg")
   background-size:contain;
   background-repeat:no-repeat;
}
like image 93
Arthur Weborg Avatar answered Oct 29 '22 17:10

Arthur Weborg


You can use:

background-size: cover;

However please bear in mind which browsers this supports. For example, this won't work in IE8 and below.

like image 38
MMM Avatar answered Oct 29 '22 15:10

MMM