views:

39

answers:

4

is the fact parent collapses when children are floating a bug?

If so why are newer browsers not fixing it

Is it intentionally? for what good reason?

I know at least 6 solutions to get around this issue, I am only asking if this is a bug or not.

Thanks

+1  A: 

When you float an element, you take it out of the flow of the page. Due to this, the parent won't expand to accommodate the child. Yes, it is intentional (and defined, I believe) behavior.

Here is a tutorial that talks about enclosing floats.

Vivin Paliath
+1  A: 

I believe thats a function of the float. You are removing the element from its location in the flow and pushing it left. The "space" that it takes up is freed. As opposed to absolute/relative positioning where the object still takes up the space.

I think that's how it goes!

tahdhaze09
Close, but you're not exactly removing it from the flow because text will properly wrap around a floated image.
Austin Fitzpatrick
+4  A: 

from: css-tricks

As anti-intuitive as collapsing seems to be, the alternative is worse. Consider this scenario:

If the block element on top where to have automatically expanded to accomodate the floated element, we would have an unnatural spacing break in the flow of text between paragraphs, with no practical way of fixing it. If this were the case, us designers would be complaining much harder about this behavior than we do about collapsing.

Collapsing almost always needs to be dealt with to prevent strange layout and cross-browser problems. We fix it by clearing the float after the floated elements in the container but before the close of the container.

Austin Fitzpatrick
thanks, can you please give me a scenario where a strange layout will happen
adardesign
Its in the article. With a picture and everything :) Check the "The Great Collapse" subheading.
Austin Fitzpatrick
Thanks, Got it... http://css-tricks.com/wp-content/csstricks-uploads/whywecollapse.pngI think that this point is arguable
adardesign
+1  A: 

it's meant to be that way. Half way down this article there is a solution to fix some of the potential problems you have have with it.

http://www.smashingmagazine.com/2009/10/19/the-mystery-of-css-float-property/

Catfish