...

View Full Version : Help positioning a div relative to it's parent div



Darkmatter5
02-12-2009, 04:52 PM
First of all if you have this code:

<div id="wrap">
<div id="content">content</div>
<div id="footer">footer</div>
</div>

Are content and footer considered child divs of the wrap div? And is wrap considered the parent div of content and wrap?

Now here's my actual css and html


#login {
height: 70px;
min-width: 100%;
}
#yelblk_stripe {
height: 5px;
min-width: 100%;
background: url(../images/stripe.png) repeat-x;
}

<div id="login">
<div id="yelblk_stripe"></div>
<div id="yelblk_stripe" style="position: absolute; bottom: 0px; left:0px; clear: both;"></div>
</div>


How can I get the bottom "yelblk_stripe" div to be along the bottom of the "login" div NOT the page. I also failed to mention the "login" div is located about 1/4 of the way down the page.

jlhaslip
02-12-2009, 05:28 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
page title
</title>
<style type="text/css">
/*<![CDATA[*/
body { margin:0; padding: 0; height: 100%; background-color: green; }
#wrap{ }
#login { border: 1px solid black; }
#yelblk_stripe { height: 15px; bottom: 0px; clear: both;
background: url(../images/stripe.png) repeat-x; border: 1px dotted blue; background-color:white;}
/*]]>*/
</style>
</head>
<body>
<div>
<div id="wrap">

<p>
some content here above the div
</p>
<p>
some content here above the div
</p>
<p>
some content here above the div
</p>
<p>

some content here above the div
</p>
<p>
some content here above the div
</p>
<div id="login">
<p>
login content here
</p>
<p>

login content here
</p>
<div id="yelblk_stripe"></div>
</div>
</div>
</div>
</body>
</html>

marilynn.fowler
02-12-2009, 06:20 PM
They are children of the "wrap" div. However, if you want to position something relative to a containing div (as opposed to the browser window), you need to set the position attribute of the containing div to relative.

#wrap { position: relative; }

Now anything inside is positioned relative to #wrap.

Darkmatter5
02-27-2009, 03:52 PM
I'm now using this code, but the status div is displayed correctly to the right edge of the viewport, but it's displayed below and not inline to the menu and content divs. WHY??



#wrap {
width: 100%;
}
#header {
height: 80px;
width: 100%;
background-color: gray;
}
#menu {
float: left;
width: 100px;
padding: 1em;
background-color: green;
}
#content {
margin-left: 130px;
border-left: 1px solid gray;
margin-right: 330px;
border-right: 1px solid gray;
padding: 1em;
background-color: blue;
}
#status {
float: right;
margin-right: 0;
width: 300px;
padding: 1em;
background-color: red;
}

<div id="wrap">
<div id="header"></div>
<div id="menu">menu</div>
<div id="content">content</div>
<div id="status">status</div>
</div>

Excavator
02-27-2009, 03:59 PM
Hello Darkmatter5,
Floats come first. Like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html, body {
font: 12px "Comic Sans MS";
background: #FC6;
text-align: center;
}
* {
margin: 0;
padding: 0;
border: none;
}
#wrap {
margin: 30px auto;
background: #999;
overflow: auto;
}
#header {
height: 80px;
width: 100%;
background: #CCC;
}
#menu {
float: left;
width: 100px;
padding: 1em;
background: #090;
}
#content {
margin-left: 130px;
border-left: 1px solid gray;
margin-right: 330px;
border-right: 1px solid gray;
padding: 1em;
background: #00f;
}
#status {
float: right;
margin-right: 0;
width: 300px;
padding: 1em;
background: #f00;
}
</style>
</head>
<body>
<div id="wrap">
<div id="header"></div>
<div id="menu">menu</div>
<div id="status">status</div>
<div id="content">content</div>
<!--end wrap--></div>
</body>
</html>

Moved the bit in red.

Darkmatter5
02-27-2009, 04:07 PM
Thanks worked great!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum