Forum Moderators: not2easy

Message Too Old, No Replies

Relative divs don't push wrapperdiv's height

         

TeaMan

2:31 pm on Sep 11, 2010 (gmt 0)

10+ Year Member



Hi there,

Divs not sizing as people wish, seems a topic that's discussed very often, so this is probably very uninteresting. I haven't found a solution for my problem though in all those topics, so it would really help me :)
Okay, here we go:

I have this three-column, fixed-width website with a wrapper to center the whole thing. The leftmost and rightmost columns are nothing special. The middle column consists of two separate divs, a menu-div and a main-div (where the mail content is shown).
Relevant HTML looks like this (nothing too special):

<html>
<body>
<div id='wrapper'>
<div id='left'>
[left-column content]
</div> <!--- END LEFT --->
<div id='menu'>
[menu]
</div> <!--- END MENU --->
<div id='main'>
[main content]
</div> <!--- END MAIN --->
<div id='right'>
[right-column content]
</div> <!--- END RIGHT --->
</div><!--- END WRAPPER --->
</body>
</html>


Now, the relevant CSS looks like this: (widths aren't correct, because I removed margins for the troubleshooting ;) )

#wrapper{
position:relative;
margin-left:auto;
margin-right:auto;
margin-top:90px;
margin-bottom:66px;
width:960px;
background-color:#fdfefd;
}
/* Left-column */
#left{
position:absolute;
padding-left:16px;
padding-right:18px;
width:109px;
}
/* Right-column */
#right{
position:absolute;
left:759px;
top:15px;
width:166px;
height:540px auto;
}
/* Menu */
#menu{
position:absolute;
top:47px;
left:143px;
width:616px;
}
/* General page */
#main{
position:relative;
top:160px;
left:143px;
width:455px;
}


The problem here is, that nor the relative, nor the absolute elements (right, left and main) are pushing the background of the wrapper (and thus the wrapper itself, I suppose) down as the content of those elements increases. When I put the position to default, it does push it down and, for example, in the case I put the position of the right-column to relative, it does push down...
It's really mysterious in my eyes, but it's probably obvious :p

Well, thanks a lot already! :D

TeaMan

TeaMan

4:47 pm on Sep 11, 2010 (gmt 0)

10+ Year Member



Edit: Okay, I've found out why the main-div didn't seem to push it down. I just forgot to put a bottom-padding in the wrapper div to compensate for the menu being above the main-div.

But there's still the problem that the right column doesn't push it down, but I don't know if this is possible for absolute divs (I think it isn't).
Does anyone have a solution for this problem (which only occurs when there's less text in the main page then in the right column)?

rainborick

2:27 pm on Sep 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Without checking, I would say you've probably found your problem. Elements with position:absolute are removed from the normal document flow and would not affect the dimensions of the parent containing element. And, just in case, be sure to use a complete <!DOCTYPE> statement in your real code and also when you post examples so that we all know you're working in Standards Compliance Mode.

TeaMan

5:40 pm on Sep 12, 2010 (gmt 0)

10+ Year Member



Alright, then. I'll just use quite wide margins then to make sure it goes well in most cases, but it is kinda odd that this isn't normally fixable still :P

And on the doctype: yeah, just wanted to remove as many irrelevant, obvious rubbish ;) But I'll remember to notice :)

Thanks anyway! :)