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
Satya Roman
3,632 PointsWhy doesn't it work to apply only to .primary float: left ?
I was just wondering why I am not able to just apply float: left to the .primary column and then by that I've thought the following content should automatically flow around it ?
I mean its clearly not working but I can't just get into my head why. Why do I also need to apply to .secondary float: left aswell ?
1 Answer
Matt Brock
28,330 PointsHey Satya, floats are a bit tricky. Floating an element removes it from the normal document flow. You have to make sure a floated element's container is "cleared" to ensure that things don't break. I like to use a CSS utility class to be able to quickly apply a "clearfix" to any containing element so that its children can be properly floated. Here's the one I use for my projects:
.clearfix:after {
content: "";
display: table;
clear: both;
}
If I want .element to float left, then I would just do this in my CSS:
.element {
float: left:
width: 200px;
/* other styles */
}
... and this in my HTML markup:
<div class="clearfix">
<div class="element">
<!-- content here -->
</div>
</div>