Gaillen
Jun 1st, 2010, 12:53 PM
I have a full page height fixed (no scroll) background image in my design that I wanted stretched to window height but not width and centred because the image is narrow and blends with the background colour. I played with the CSS solution from tutorials by Stu Nicholls , Chris Coyier & Jennifer Kyrnin and came up with a solution that works in Firefox, Safari, & IE8 but not in Opera. In Opera it does everything but centre.
I am hoping another set of eyes might see a solution.
I have included a full sample document that is tested to work/fail and can be tested as an index.htm if you assign an image and some content to test the scrolling.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Faking a Stretched Background Image - Across the Whole Page</title>
<meta name="keywords" content="background size, background stretch,
stretched background images">
<meta name="description" content="Use the z-index property to layer your
content on top of your stretched background image.">
<style type="text/css">
body {
margin:0; padding:0;
}
html, body, #bg {
height:100%;
width:100%;
}
#bg {
position:fixed;
left:0;
right:0;
bottom:0;
top:0;
overflow:hidden;
z-index:-99;
}
#bg img {
min-height:100%;
}
#content {
width:200px;
z-index:1;
}
</style>
</head>
<body>
<div align=center>
<div id="bg">
<img style="display:block;" src="your_bg_image.gif">
</div>
</div>
<div id="content">
//your content here!
</div>
</body>
</body></html>
Cheers! :confused:
I am hoping another set of eyes might see a solution.
I have included a full sample document that is tested to work/fail and can be tested as an index.htm if you assign an image and some content to test the scrolling.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Faking a Stretched Background Image - Across the Whole Page</title>
<meta name="keywords" content="background size, background stretch,
stretched background images">
<meta name="description" content="Use the z-index property to layer your
content on top of your stretched background image.">
<style type="text/css">
body {
margin:0; padding:0;
}
html, body, #bg {
height:100%;
width:100%;
}
#bg {
position:fixed;
left:0;
right:0;
bottom:0;
top:0;
overflow:hidden;
z-index:-99;
}
#bg img {
min-height:100%;
}
#content {
width:200px;
z-index:1;
}
</style>
</head>
<body>
<div align=center>
<div id="bg">
<img style="display:block;" src="your_bg_image.gif">
</div>
</div>
<div id="content">
//your content here!
</div>
</body>
</body></html>
Cheers! :confused: