Forum Moderators: not2easy

Message Too Old, No Replies

Float content and expanding div's.

         

base

11:23 am on Nov 15, 2008 (gmt 0)

10+ Year Member



Could somebody tell me please, why doesn't a div expand when it's filled with floated content?

Wouldn't it be easier when it just would?
Is there a reason for this?

I am sorry, and it was probably answered a million times before but I'm curious.
Thanks in advance.

swa66

11:55 am on Nov 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The standard is that it doesn't.

Adding a clearing element or alternatively using "clearfix" (be careful what hacks you get) is the easiest solution.

"float" is inherited form the old <img align="left"> and that could go lower than the current paragraph where it sat in too ... It actually makes sense is doesn't expand its paragraph and lets the next paragraph also go next to the image.

base

12:03 pm on Nov 15, 2008 (gmt 0)

10+ Year Member



Well i finally found the solution to the problem that's been bugging me for a while and thanks to this forum.

I just added a spacer div in the bottom of the parent tag using the following attributes:

height:30px; /* space wanted
clear:both; /* required
width:100px; /* not crucial

This works perfectly for me (in combination with the code you supplied me with before swa66.).

Thanks again and thanks a lot!