Solved

Browser Support for background-size css property on body tag

Posted on 2010-11-25
11
574 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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)

911 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

22 Experts available now in Live!

Get 1:1 Help Now