3 ms·
I'm not really a front-end kind of person, but whenever I've written any CSS this has, I think, literally always bitten me. I try to read about it and understan
by OJFord 10y ago
I'm not really a front-end kind of person, but whenever I've written any CSS this has, I think, literally always bitten me. I try to read about it and understand it 'properly' every time, but clearly I never do.
Why is the unhacked behaviour desirable? If I put a thing in a thing, surely I want it to stay in the thing?!
- masklinn 10y agoBecause 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 http://codepen.io/anon/pen/ggGgWb Here's the "clearfixed" version which is nonsensical: http://codepen.io/anon/pen/xgXgry 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.
- schneidmaster 10y agoThis is a great explanation, thanks. I'd never quite understood this either.
- lomnakkus 10y agoThose demos look completely identical on my browsers (Chromium, Firefox). The CSS change is there, but the rendered output looks identical.
- masklinn 10y agoThat is odd, I just opened them in Firefox 51 and I do get the rendering I was expecting: http://imgur.com/a/Bke7v http://imgur.com/a/Bke7v
- lomnakkus 10y agoOh, 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!
- masklinn 10y agoAh, makes sense, I should probably have explicitly set a small font size but completely forgot about the possibility of that issue.