PDA

View Full Version : div placement


blimp
08-04-2009, 03:54 AM
I'm having trouble understanding what I'm doing wrong.

In <div id="left"> I need to place a few boxes that sit underneath each other.

So fare I have set <div id="box1"> position to relative and added left: 104px and top: 108px placement. This box is now sitting exactly where I want it.

Now I'd like to add another box beneath called <div id="box2">. I've given it a height, width and set the position to relative, but the box doesn't position in the top left corner of <div id="left">

Why is this so?


<!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=UTF-8" />
<title></title>
<style type="text/css">
body {
margin: 0px;
padding: 0px;
}

#wrapper {
height: 780px;
width: 850px;
margin:0px auto;
}
#left {
height: 780px;
width: 363px;
float: left;
background-color: #666;
position: relative;
margin: 0px;
padding: 0px;
}
#right {
height: 780px;
width: 487px;
float: left;
background-color: #999;
position: relative;
}
#slideshow_container {
height: 567px;
width: 388px;
position: relative;
left: 0px;
top: 108px;
background-color: #e2e3e4;
}
#slideshow {
height: 548px;
width: 369px;
position: relative;
left: 9px;
top: 8px;
background-color: #FFF;
}
#box1 {
position: relative;
height: 82px;
width: 251px;
left: 104px;
top: 108px;
background-color: #e2e3e4;
}
#box2 {
height: 150px;
width: 251px;
background-color: #F00;
position: relativ;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="left">
<div id="box1">BOX1</div>
<div id="box2">BOX2</div>
</div>
<div id="right">
<div id="slideshow_container">
<div id="slideshow"></div>
</div>
</div>
</div>
</body>
</html>

edbr
08-04-2009, 04:06 AM
#box2 {
height: 150px;
width: 251px;
background-color: #F00;
position: relativ;
}
typo , should be relative
add clear: left:

blimp
08-04-2009, 04:32 AM
edbr,

I added clear left and that didn't work?


<!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=UTF-8" />
<title></title>
<style type="text/css">
body {
margin: 0px;
padding: 0px;
}

#wrapper {
height: 780px;
width: 850px;
margin:0px auto;
}
#left {
height: 780px;
width: 363px;
float: left;
background-color: #666;
position: relative;
margin: 0px;
padding: 0px;
}
#right {
height: 780px;
width: 487px;
float: left;
background-color: #999;
position: relative;
}
#slideshow_container {
height: 567px;
width: 388px;
position: relative;
left: 0px;
top: 108px;
background-color: #e2e3e4;
}
#slideshow {
height: 548px;
width: 369px;
position: relative;
left: 9px;
top: 8px;
background-color: #FFF;
}
#box1 {
position: relative;
height: 82px;
width: 251px;
left: 104px;
top: 108px;
background-color: #e2e3e4;
}
#box2 {
height: 150px;
width: 251px;
background-color: #F00;
position: relative;
clear: left;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="left">
<div id="box1">BOX1</div>
<div id="box2">BOX2</div>
</div>
<div id="right">
<div id="slideshow_container">
<div id="slideshow"></div>
</div>
</div>
</div>
</body>
</html>


So what I need it t do is sit in the top left corner of <div id="left">

example

http://img17.imageshack.us/img17/3125/picture2lun.jpg

blimp
08-04-2009, 05:16 AM
edbr, I've deleted some of the divs to simplified it but its still not working?

<!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=UTF-8" />
<title></title>
<style type="text/css">
#wrapper {
height: 780px;
width: 850px;
margin:0px auto;
}
#left {
height: 780px;
width: 363px;
background-color: #CCC;
}
#box1 {
background-color: #F6C;
height: 52px;
width: 251px;
position:relative;
top:108px;
left:104px
}
#box2 {
background-color: #F66;
height: 150px;
width: 251px;
position:relative;
clear:left;
top:197px;
left:104px
}
</style>
</head>
<body>
<div id="wrapper">
<div id="left">
<div id="box1">BOX1</div>
<div id="box2">BOX2</div>
</div>
</div>
</body>
</html>

edbr
08-04-2009, 05:38 AM
you are using
top:108px; left:104px
to position them ,
delete these and they wil float left as (i think)you want

blimp
08-04-2009, 05:57 AM
edbr,

I actually need box1 to be positioned (top:108px; left:104px) because that's where I want that box to be, then I want box2 beneath it.

I've added some images below to better explain.

This is what the code is doing now:
http://img518.imageshack.us/img518/3497/picture3k.jpg

and this is what I want it to look like:
http://img518.imageshack.us/img518/4905/picture31bqg.jpg

does it make sense?

edbr
08-04-2009, 06:24 AM
yes now

give them the same marginn left and the first one a margin top

#box1 {
background-color: #F6C;
height: 52px;
width: 251px;
float:left;
position:relative;
margin-top:108px;
margin-left:104px
}
#box2 {
background-color: #F66;
height: 150px;
width: 251px;
position:relative;
float: left;
clear:left;
margin-top:20px;
margin-left:104px
}

and give box 2 the top margin you want to seperate them also i would float them both left

blimp
08-04-2009, 06:59 AM
edbr, thank you so much I've been tearing my hair out about this all day. I sort of get confused with when to use float. I understand when to use clear but I'll have to do some more reading on floats.....

Cheers again