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 Basics (2014) Basic Layout Floats

rajbee
rajbee
6,657 Points

floating - positioning of the second div

At 3:50, the second div/column is floated to the right. Why does the footer go below the first div and the second column is halfway into the footer ?

1 Answer

luis betancourt
luis betancourt
1,236 Points

That happens because when you float something to the right or left. it causes that floated element to be moved left or right, which is what you want but the browser starts treating that floated element as if it's height was 0px.

to solve this issue you add a clearfix class to the parent that holds the floated div's. You can see that the css is targeting the parent's after pseudo element. This is an invisible element that every element has after it's closing tag.

.clearfix:after {
  content: "";
  display: table;
  clear: both;
}
<div class="clearfix">
      <div class="float-right">Float to the right</div>
      <div class="float-left">Float to the left</div>
</div>
Aie Wan
Aie Wan
4,803 Points

Great explanation! Thanks!