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 trialkaran Badhwar
Web Development Techdegree Graduate 18,135 PointsHard time understanding Float
I am having hard time understanding float please if someone can explain it to me 1)- some elements float well in the same line while others go out of the container ? like how , why?
2)- .article-content going out of the container but why the width and height of the container depends on the content if I give (image float left) and (article-content Float right) why is that overflowing the article I know Float takes the element out of the flow of the Page but why the container gets narrower?
3) why did he give Display: table, To make it Display: block we could have have given that display : block
4)- what actually with the .group::after i did not understand it how it clears everything which area it did targets ?
2 Answers
Jason Larson
8,361 PointsSome elements float well in the same line when it's only one of the elements that are floated because the element that isn't floated is giving definition to the container. This leads into your 2nd question about why the element collapsed when both elements were floated. You are right that it has to do with Float taking the element out of the flow of the page. In this case, when the 2 elements were all that existed within the container and both were Floated, then there was nothing inside the container, which caused it to collapse, which in turn caused the floated elements to overflow.
I'm not sure exactly why he used display: table
rather than display: block
. I've never used display: table
, but when I looked it up, it seems as though it acts very similarly to inline-block, where it doesn't take up the entire line, but it puts it in its own block, similar to block. He may have been able to use display: block, but my guess is that it would have extended further than he wanted it to, so he used display: table to limit the amount of the element that it used.
The after pseudo element is being applied to the .group class, which he applied to all the <article> elements. The clear property specifies what should happen with the element that is next to a floating element, so when he used clear: both, it told the browser to push the element down below both left and right floated elements. This basically just gave the element something inside of it (from the content property), and told it to push that content down below the floated elements, which meant that they wouldn't overflow because the element wouldn't collapse.
karan Badhwar
Web Development Techdegree Graduate 18,135 PointsThankyou Jason, For the easy explanation !!!