Page 1 of 1
Two column CSS
Posted: Thu Jul 12, 2007 1:49 am
by alex.barylski
A common problem I experience in making two column designs is that because I also utilize a header/footer approach one of the columns always ends up bleeding through and under the footer.
Code: Select all
<div style='position: absolute; '>
Left Column
</div>
<div style='position: relative; left: 50%; width: 50%'>
Right Column
</div>
If
Left Column is now greater in content than
Right Column because of the
absolute identifer the content doesn't "push" the DIV down to reflect it's content. However
Right Column because it's
relative does adjust as expected. I have tried wrapping the two DIV's inside a container DIV but that doesn't work. I was sure I seen a CSS property which "cleared" some attribute and forced the DIV to adjust.
I'm not sure if the right DIV can be a child of the other or visa-versa as one of the columns is being added programatically...if that makes anysense...so ideally I need a layout which is dual sibling DIV's which render nicely as expected...
Any ideas?

Posted: Thu Jul 12, 2007 4:37 am
by Gente
Maybe you are looking for something like this?
Code: Select all
<div style="width:800px; overflow:hidden;">
<div style="float:left; width: 50%;">
Left Column
</div>
<div style="float:left; width: 50%;">
Right Column
</div>
</div>
Posted: Thu Jul 12, 2007 5:15 am
by alex.barylski
Hmmmmm...that might work
Thanks for that

Posted: Thu Jul 12, 2007 5:38 am
by matthijs
Gente's solution works fine. Watch out with the percentages though. Sometimes 50% + 50% is > 100% due to rounding errors. And in that case IE drops one of the floats below the other. I usually set the percentages a fraction lower, to keep a bit of "margin"
Posted: Thu Jul 12, 2007 5:50 am
by alex.barylski
matthijs wrote:Gente's solution works fine. Watch out with the percentages though. Sometimes 50% + 50% is > 100% due to rounding errors. And in that case IE drops one of the floats below the other. I usually set the percentages a fraction lower, to keep a bit of "margin"
Thanks for the heads up. I'll keep that in mind.

Posted: Thu Jul 12, 2007 9:08 am
by TheMoose
Just to kinda add to the mix:
Code: Select all
<div style="clear:both;"> </div>
That will make sure any currently floating elements don't float over that div and below. I add the (code for a single space character) because IE6 needs data in the div for it to render properly (surprising, isn't it).
Posted: Thu Jul 12, 2007 9:32 am
by JayBird
or, you can put the left and right divs in a container then add this style to the container
Code: Select all
.container:after{ content: "."; display: block; height: 0; font-size:0; clear: both; visibility:hidden; }
Posted: Fri Jul 13, 2007 4:34 pm
by RobertGonzalez
IE won't understand the :after pseudo class though.
Are you trying make your footers always end up below the body (nav + content)? There are a few easy ways to do that.
Posted: Sat Jul 14, 2007 1:32 am
by matthijs
There is no talk of a footer at all.
So it seems everybody is so eager to help, they post solutions to a problem which doesn't (yet) exist. Can you imagine how helpful this forum is!

Posted: Sat Jul 14, 2007 1:37 am
by alex.barylski
TheMoose wrote:Just to kinda add to the mix:
Code: Select all
<div style="clear:both;"> </div>
That will make sure any currently floating elements don't float over that div and below. I add the (code for a single space character) because IE6 needs data in the div for it to render properly (surprising, isn't it).
I have used this:
Works fine in IE 6.0.2900
I apologize for the confusion but yes, there was a footer. Moose's suggesiton worked but I had to place that DIV immediately after the two columns to clear their float-ness and to push the footer down instead of under-lapping them.
Posted: Sat Jul 14, 2007 1:47 am
by matthijs
If you already have a footer in place, then you don't need a separate element. Clear the footer itself. Keeps your HTML a bit cleaner.