Forum Moderators: not2easy

Message Too Old, No Replies

how to stretch wrapper div

         

Tk_liv

6:49 am on Aug 4, 2009 (gmt 0)

10+ Year Member



hi
I have noticed,when inserting a child div with floatiing positioning,the parent div dose not streach automatically with its background color.I want wrapper div to streach all the way to bottom of its childs divs.Can anybody help me to fix this?

Thanks in advance
Tk

swa66

11:43 am on Aug 4, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's intended behavior.

Floats are removed from their parents flow (they still interact with it, but are not part of it.)

To get wha tyou seek to happen:
- either float the parent too (floats to encompass their children, it's one of the exceptions, but in general this leads to more problems instead of less.
- add an element after the floated one but inside the parent (e.g.

<br class="clear" />
) and then do not float this element, but do give it the clear property (e.g.
.clear {clear:both;}
)
- search for clearfix, it's a variation on the above, but does so using :after pseudo elements instead. Take care not to copy the hacks many examples out there contain as well IE6 doesn't need this, it does the entire thing wrong anyway.