Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Because the original purpose of floats is not layout (where you want the thing to stay in the other thing) it's typographic floats, like pull quotes or info boxes or pictures. In that case, even if your float is in a paragraph you don't want to "expand" the paragraph past the end of the float if the float is longer than the paragraph, you want the following paragraph to be laid out around the float instead.

Here's a demo: http://codepen.io/anon/pen/ggGgWb

Here's the "clearfixed" version which is nonsensical: http://codepen.io/anon/pen/xgXgry

That floats were press-ganged into layout does not mean their basic behaviour is bad, it just means they were used for something that was never intended (due to a lack of actual layout tools in CSS until CSS3) and they were not very good at it.

And note that the lack of layout tools was not limited to "applicative" layouts, most papers are laid out in multiple text columns yet that fairly simple and common layout was not supported either until CSS3.



Those demos look completely identical on my browsers (Chromium, Firefox). The CSS change is there, but the rendered output looks identical.


That is odd, I just opened them in Firefox 51 and I do get the rendering I was expecting: http://imgur.com/a/Bke7v


Oh, I see what happened. I have a minimum font size which makes the first paragraph tall enough so that it wraps all the way around the image -- so the clearfix is effectively redundant with my font sizes. The image clears it up, thanks!


Ah, makes sense, I should probably have explicitly set a small font size but completely forgot about the possibility of that issue.


This is a great explanation, thanks. I'd never quite understood this either.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: