Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Foundations The Box Model Floats

Cameron Monzon
Cameron Monzon
7,115 Points

Why use floats?

This video makes floating seem inefficient.

When he floats the image left and the text is wrapping he positions the text to the right by floating it. This seems to screw up everything because the text box is thrown off by it. Isnt it best to position by means of margins and padding within the box rather than floating everything and then having to clear the float? Even clearing the float seems strenuous and not best practice.

1 Answer

We do have alternatives, kind of (display: inline-block and display: table, to name a couple), but they have a lot of limitations. Despite the shortcomings that floats have, they've been the accepted standard for a long time because of how easy they are to use and understand, even if they are inefficient.

But yes. Floats do suck.

Fortunately, we're getting a much better layout system with flexbox. Flexbox is the future of layout on the web, and it's really starting to take off. Once IE8 and IE9 fall out of favor (hopefully in the next decade or so), we can begin to use flexbox with only vendor prefixes. Until then, it's floats and clearfixes.

If you continue in the CSS Foundations course, Guil should talk some about flexbox, though it's kind of an old course and flexbox was in a different stage of life back then.

I'd encourage you to look into Guil's newer course on Layout Techniques, where he covers all kinds of layout modules (display modes, floats, flexbox, positioning, and more).

Hope this helps!