Solved

Browser Support for background-size css property on body tag

Posted on 2010-11-25
11
573 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
Comment Utility
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
Comment Utility
thanks that worked in Firefox.  Anyone else have any IE ideas?
0
 
LVL 13

Expert Comment

by:numberkruncher
Comment Utility
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
 
LVL 13

Expert Comment

by:numberkruncher
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:cgray1223
Comment Utility
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
Comment Utility
Which version of IE are you using because it seemed to work on my version?
0
 
LVL 13

Expert Comment

by:numberkruncher
Comment Utility
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
Comment Utility
Did you include the <!DOCTYPE tag? that could be the difference between failure and working?
0
 

Author Comment

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

Expert Comment

by:numberkruncher
Comment Utility
No problem, glad that I could help!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now