# [web] CSS div positioning problem

This topic is 4356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

OK, I am using CSS and in it I have defined:
#DirectoryMenu
{
position:absolute; top:0.25em;
max-width:16em;
border-style:double;
background-color:#FFCC99;
}

#Content
{
position:absolute; left:18em; top:0.25em;
}


Then in the body of my webpage I have
<body>
....a bunch of code....
</div>

<div id="Content">
.....a bunch of code.....
</div>
</body>


This works OK for now, but what I want to do is have the DirectoryMenu (whose width will dynamically adjust depending on the length of what is displayed in it)on the top left, and the Content beside it, running from the right side of the DirectoryMenu to the right side of the window. Currently I have set the Content section to an absolute left position because I can not figure out how to have it "float" over to the right side of the Directory Menu. I have tried adding "float:left;" to the Content, but then it floats over top of the DirectoryMenu, and if I try using relative positioning instead of absolute, then the Content appears underneith the DirectoryMenu. To see what it currently looks like go here. Any help would be appreciated. Thanks.

##### Share on other sites
Dont position either of them using absolute.
Make both of them float:left. And make the content div clear:right.

##### Share on other sites
Quote:
 Original post by PhilMortonDont position either of them using absolute.Make both of them float:left. And make the content div clear:right.

I tried this but the Content section appeared below the DirectoryMenu, not beside it. I should mention that in my DirectoryMenu and Content sections there are breaks (br /); it is not one big object like a table or something. Does anyone else have any ideas? Thanks

##### Share on other sites
I'm still having this problem if anybody has a potential solution for me. Thanks.

##### Share on other sites
hmm, you could give this tutorial a go;
http://www.456bereastreet.com/lab/developing_with_web_standards/csslayout/2-col/

Or search for "two column layout div css" to find other tutorials on google...

##### Share on other sites
Something really basic would be:

&lt;html&gt;&lt;head&gt;&lt;style type="text/css"&gt;#menu {	float: left;	width: 20%;	border: 0.1em solid #000;	padding: 0.5em;}#content {	float: right;	width: 70%;	border: 0.1em solid #000;	padding: 0.5em;}&lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div id="menu"&gt;  <ul>   <li>Item 1</li>   <li>Item 2</li> </ul></div>&lt;div id="content"&gt;<p>My Content</p><p>And other stuff like that</p></div>&lt;/body&gt;&lt;/html&gt;

If you want to include somthing like a footer box below both of them, just put another div below them with the style clear: all and it should stretch across the page.

##### Share on other sites
Awesome, thanks for the tutorials. They helped alot, but I am still having some trouble. I now have 4 div sections: Heading, DirectoryMenu, Pictures (content), and Container which holds all of the other divs. Here is how I have them defined now:
/* Background properties */body{	padding:0;	margin:0;	background-color:#FFFFFF;	color:#000000;}/* Everything is contained within this div */#Container{	width:100%;	margin:0 auto;}/* Heading properties */#Heading{	border-style:solid; border-color:#000000; border-width:thin;	background-color:#FFFFCC;	margin:0.25em;	font-weight:bold;	text-align:center;	color:#0000CC;	clear:both;}/* Directory Menu properties */#DirectoryMenu{	float:left;	max-width:35%;	border-style:double;	background-color:#CCCCCC;	padding:0.25em;	margin:0.25em;}/* Pictures section properties */#Pictures{	margin:0.25em;	padding:0.25em;}

and this is the format they are defined:
<div id="Container">   <div id="Heading">....</div>   <div id="DirectoryMenu">....</div>   <div id="Pictures">....</div></div>

Problem 1 - The Pictures section contains 2 tables; 1 for the Pictures, and another for the Pages (i.e. if there are 100 pictures and you are showing 10 pictures per page, you will need 10 pages). I want the Pictures section to extend to the right edge of the screen (i.e. the right edge of the Container div) so that the tables extend from the left edge of the DirectoryMenu to the right edge of the screen. I have tried making the tables widths 100%, but then it makes the tables width the size of the screen width, so it extends past the right edge of the screen quite a bit. If I don't specify a width in the tables (as it currently is) then the tables only extend as much is needed to display their content. How could I get the tables to extend to the right edge of the screen?

Problem 2 - The Pictures section does not remain a rectangle. That is, if the Pictures section extends past the DirectoryMenu section, then the Pictures section moves over to the left edge of the screen. Is there any way I could specify it not to do this?

To see the page as it currently is go here. Scroll all the way to the bottom to see Problem 2.

Any more help would be very appreciated. Thanks

##### Share on other sites
Instead of floating the directory menu left, you could float the pictures section right. That will solve #1 (because 100% table width will be picture container width) and #2.

##### Share on other sites
Quote:
 Original post by SanderInstead of floating the directory menu left, you could float the pictures section right. That will solve #1 (because 100% table width will be picture container width) and #2.

I tried this and it seemed to correct the width problem, but it also pushed the Pictures section down underneith the DirectoryMenu section. How could I fix this problem so it stays beside the DirectoryMenu, not under it? Thanks

1. 1
2. 2
frob
16
3. 3
4. 4
5. 5

• 20
• 13
• 14
• 76
• 22
• ### Forum Statistics

• Total Topics
632139
• Total Posts
3004369

×