Forum Moderators: not2easy
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<style type="text/css">
html, body { margin: 0; padding: 0; width: 100%; height: 100%; }
img { border: 0; }
img#back
{
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: -1;
}
div#content
{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<img id="back" src="road.jpg" alt="" title="" />
<div id="content">
<p>My first paragraph.</p>
<p>My first paragraph.</p>
<p>My first paragraph.</p>
<p>My first paragraph.</p>
</div>
</body>
</html>
I had to set content div to position: absolute on 0,0 but without that there was always small vertical scrollbar.Fix by setting overflow:hidden on the body and html as in:
html, body {margin:0; padding:0; width:100%; height:100%; overflow:hidden;}Where #back is the id of the (unsized) "background" image that will be placed into the body - or the id of the element containing the image if using a strict doctype. This method doesn't need the real content to be wrapped by a positioned "container" div (like div#content). Tested in op9*, ie6-8, f3*, winSafari3&4.
#back {position:absolute; z-index:-1; width:100%; height:100%;}
how can I place text in a div & then have that div always be 1) centered horizontally & 2) fixed vertically, as the browser window size changes (& the image expands or contracts)...?Check out Vertical Centre [webmasterworld.com] in the forum library. Older, but lots of information about "why" as well.