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 Layout Basics Page Layout with the Float Property How Floats Work

Marc Aldrin Dela Cruz
Marc Aldrin Dela Cruz
2,896 Points

About how float works on a "block" element.

We all know that inline or inline-block in css can make elements in the same line. given there is enough space for both of them. is it still necessary to use float in an inline elements.?

How about in block elements? should i convert them first to an inline element or I'll just use the "float"? to make them inline or with another elements and please remind me of what is the default padding and margin of a block element thanks.

1 Answer

Shay Paustovsky
Shay Paustovsky
969 Points

Hi Marc,

The display mode doesn't really matters when using floats because in essence what floats do that inline-block display mode doesn't is remove the element from the normal document flow. Therefore it's like absolute positioning but not exactly, the elements achknowledge the existance of it but still collapse, if the container of the float has a display set to 'block'.

Block elements by default have top & bottom margins and it really depends on the elements. Also don't forget collapsing margins between block-level elements.

Hopefully I've cleared some confusions,

Shay