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 How to Make a Website Adding Pages to a Website Style New Pages

I was wondering if you could explain the bug that caused the error and why the clear: both; line fixes the error

I was just looking for a little more clarification on why this bug pops up and why that line of code fixes it.

4 Answers

Charles Gray
Charles Gray
19,470 Points

if you don't use a clear both after a floated item, everything after it follows the float rule.

James Alker
James Alker
8,554 Points

Basically 'float' removes the element from the normal document flow, thus allowing elements after it to flow around it. Adding the 'clear' property pushes all following elements down below the floated object.

as i saw float applied only for "header" and "gallery", i wonder how 'float' concerns the element that is not a child of float.

Charles Gray
Charles Gray
19,470 Points

if one item is floated other items ignore it and acts like that floated item isn't there. So it could affect the rest of the website if it's not cleared.