brettj
10-27-2006, 05:49 AM
I thought I finally had a grasp of how relative and absolute positioning worked, then I stumbled upon this problem. How do I give to divs a relitive position when they share the same parent/container? The second one always get's pushed down. Here's an example:
<!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>Untitled Document</title>
<style type="text/css">
#wrap {
width: 760px;
margin: auto;
}
#header {
background: #000;
width: 760px;
height: 250px;
}
#box1 {
background: #0000ff;
width: 150px;
height: 100px;
position: relative;
left: -200px;
}
#box2 {
background: #ff0000;
width: 150px;
height: 100px;
position: relative;
top: 10px;
left: 810px;
}
</style>
</head>
<body>
<div id="wrap">
<div id="header">
<div id="box1"></div>
<div id="box2"></div>
</div>
</div>
</body>
</html>
The red box should only be hanging 10px below the top of the black one. I don't want to use absolute positioning because it causes the appearance of the horizontal scroll bar on lower resolution screens. It should appear that both the red and blue boxes are not being fully displayed under 800x600 resolution (and no horizontal scroll bar to see the rest).
Hope that all makes sense. It seems like a simple problem that has an easy fix. I just don't know what it is and I couldn't find the answer on my own. Thanks for the help.
<!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>Untitled Document</title>
<style type="text/css">
#wrap {
width: 760px;
margin: auto;
}
#header {
background: #000;
width: 760px;
height: 250px;
}
#box1 {
background: #0000ff;
width: 150px;
height: 100px;
position: relative;
left: -200px;
}
#box2 {
background: #ff0000;
width: 150px;
height: 100px;
position: relative;
top: 10px;
left: 810px;
}
</style>
</head>
<body>
<div id="wrap">
<div id="header">
<div id="box1"></div>
<div id="box2"></div>
</div>
</div>
</body>
</html>
The red box should only be hanging 10px below the top of the black one. I don't want to use absolute positioning because it causes the appearance of the horizontal scroll bar on lower resolution screens. It should appear that both the red and blue boxes are not being fully displayed under 800x600 resolution (and no horizontal scroll bar to see the rest).
Hope that all makes sense. It seems like a simple problem that has an easy fix. I just don't know what it is and I couldn't find the answer on my own. Thanks for the help.