Solved

Browser Support for background-size css property on body tag

Posted on 2010-11-25
11
577 Views
Last Modified: 2012-05-10
Hello,

I'm using the below to stretch a background image all the way down to the bottom of my webpage, but the background-size seems to only do that for chrome and not IE and Firefox.  In IE and Firefox it only vertically spans a quarter of the page....any ideas?

body{
      background-image: url(images/bg_home.png);
      background-repeat: repeat-x;
      background-size: 100%;
}
0
Comment
Question by:cgray1223
  • 8
  • 3
11 Comments
 
LVL 13

Expert Comment

by:numberkruncher
ID: 34214315
It isn't supported in IE, but in FireFox I believe that you can do it with:
body{
      background-image: url(images/bg_home.png);
      background-repeat: repeat-x; 
      background-size: 100%;
      -moz-background-size: 100%;
}

Open in new window

0
 

Author Comment

by:cgray1223
ID: 34214351
thanks that worked in Firefox.  Anyone else have any IE ideas?
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 34214364
What about putting an IMG tag behind your main page DIV and have it stretched to full width and height with fixed position?

You would need to use z-order CSS attribute to achieve this.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 13

Expert Comment

by:numberkruncher
ID: 34214370
Here is an example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Demo Page</title>
		<style type="text/css">
			html, body {
				margin: 0;
				padding: 0;
			}
			img.bkgnd {
				position: fixed;
				top: 0; left: 0;
				width: 100%;
				height: 100%;
				z-index: -1000;
			}
		</style>
	</head>
	<body>
		<img class="bkgnd" src="test.jpg" />
		<h1>Demo Page</h1>
		<div>
			Your stuff!
		</div>
	</body>
</html>

Open in new window

0
 
LVL 13

Accepted Solution

by:
numberkruncher earned 500 total points
ID: 34214377
Actually it is probably a good idea to include print media tag so that background is not printed!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Demo Page</title>
		<style type="text/css">
			html, body {
				margin: 0;
				padding: 0;
			}
			@media screen {
				img.bkgnd {
					position: fixed;
					top: 0; left: 0;
					width: 100%;
					height: 100%;
					z-index: -1000;
				}
			}
			@media print {
				img.bkgnd {
					display: none;
				}
			}
		</style>
	</head>
	<body>
		<img class="bkgnd" src="test.jpg" />
		<h1>Demo Page</h1>
		<div>
			Your stuff!
		</div>
	</body>
</html>

Open in new window

0
 

Author Comment

by:cgray1223
ID: 34214475
Great idea numberkruncher!  It looks great on firefox and chrome but in IE it covers up the header and div text.  When I inspect the contents the text element is there....but it doesn't show in IE
<html>
	<head>
		<style type="text/css">
			html, body {
				margin: 0;
				padding: 0;
			}
			@media screen {
				img.bkgnd {
					position: fixed;
					top: 0; left: 0;
					width: 100%;
					height: 100%;
					z-index: -1000;
				}
			}
			@media print {
				img.bkgnd {
					display: none;
				}
			}
		
		</style>
	</head>
	<body>
		<img class="bkgnd" src="images/bg_home.png" />
		<h1>Demo Page</h1>
		<div>
			Your stuff!
		</div>
		
	</body>
</html>

Open in new window


0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 34214490
Which version of IE are you using because it seemed to work on my version?
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 34214500
The only way that I can make that example fail is with "Quirks Mode" emulation in IE.
0
 
LVL 13

Assisted Solution

by:numberkruncher
numberkruncher earned 500 total points
ID: 34214503
Did you include the <!DOCTYPE tag? that could be the difference between failure and working?
0
 

Author Comment

by:cgray1223
ID: 34214515
I wasn't including the doctype, that fixed it!  Thanks for all the help!!
0
 
LVL 13

Expert Comment

by:numberkruncher
ID: 34214520
No problem, glad that I could help!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question