Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS

Jacob Miranda
Jacob Miranda
18,783 Points

Layout: Float vs Display: Inline-block ?

I constantly see Float: Left/Right used for laying out sections of a webpage, but I have recently switched over to using the property/value pair of Display: Inline-block. Through my experience, I have found it to work better and is a lot less stressful when getting it to work properly. I also don't have to worry about clearfixes and any other headaches of forgetting to add something.

The one thing to keep in mind with displaying an element with inline-block is that you must have the closing tag and opening of the next element side-by-side.

<div>Hello world!</div><div>Hello other world!</div> A space character will be rendered as a few pixels and may mess up your layout a bit.

If anyone has an opinion of using one versus the other, please discuss!

1 Answer

Jeff Lemay
Jeff Lemay
14,267 Points

Using inline-block is used more now that box-sizing:border-box is available in more browsers.