I'm working on a two-column CSS website. I want to make a nice effect of overlapping boxes, but I can't get one thing to work.
First, here's all the code needed:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test Page</title>
<style type="text/css">
body {
background-color: #FFFFFF;
color: #333333;
font-family: Arial;
font-size: 1em;
text-align: center;
margin-top: 0px;
}
#wrapper {
margin-left: auto;
margin-right: auto;
width: 800px;
background-image: url(bg_gray.png);
background-repeat: repeat-y;
}
#header {
margin-left: auto;
margin-right: auto;
background-color: #CCCCCC;
height: 50px;
width: 700px;
position: relative;
right: 50px;
}
#sidebar {
position: absolute;
width: 200px;
background-color: #333333;
color: #CCCCCC;
}
*:first-child+html #sidebar { /* IE7 */
position: absolute;
width: 200px;
margin-left: -100px;
background-color: #2a2a2a;
color: #CCCCCC;
}
#content {
background-color: #999999;
position: relative;
width: 600px;
left: 200px;
top: -25px;
}
*:first-child+html #content { /* IE7 */
background-color: #999999;
position: relative;
width: 600px;
left: 100px;
top: -25px;
}
#footer {
position: relative;
margin-left: auto;
margin-right: auto;
width: 800px;
font-size: .75em;
color: #999999;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="header">
Header
</div>
<div id="sidebar">
Sidebar<br />
Sidebar<br />
Sidebar<br />
Sidebar<br />
Sidebar<br />
Sidebar<br />
Sidebar<br />
Sidebar<br />
Sidebar<br />
Sidebar<br />
</div>
<div id="content">
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
Content<br />
</div>
</div>
<div id="footer">
Footer
</div>
</body>
</html>
Put that in a text file and save it as an HTML document to view it. The picture used in the CSS is the one at the bottom of my post--save that in the same location as the HTML.
Alright, now open it up and look at the file. See the problem? The sidebar stretches too far. When I used borders to determine what the problem was, I saw that #wrapper was stretching too far. 25px too far.
I assume it's simply stretching too far because of the negative margins of the content (it's stretching to accommodate the entire #content div, but it only needs to stretch to accommodate #content's height minus the 25px negative margin).
Any thoughts on how I can fix this?