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

confused by the concept of clearfix moving an element below floated elements - z-index?

I'm a bit confused by what Guil means here when he says that adding the clearfix class to the parent element, that holds floated elements, makes the parent element move below the floated elements. Does this mean that the parent's element's z-index ends up indirectly being lower than that of the floated elements? Could one word this by saying that by adding the clearfix class to the parent elements, the parent elements move behind the floated elements on the web page's z-index/axis?

1 Answer

Great question. Clearfix and z-index are two different things. You attach the clearfix to the parent element when it has floated children. Often when items are floated there is container collapse because the floated items are taken out of the normal flow. The clearfix creates an "empty" element that allows the parent element to clear its children and correct this issue.

z-index is for positioned elements only: position: absolute; position: fixed, etc. It establishes a stacking order for elements. Here is some more info on z-index.