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 trialBartlomiej Zabielski
Courses Plus Student 10,363 Pointsfloats with Guil Hernandez
In the video Floats by Guil Hernandez where does he calculate the width:45.5% for the two images .resports and .tips.
I tried to use dev tools but can't figure it out
3 Answers
Bartlomiej Zabielski
Courses Plus Student 10,363 Pointshey I get that we need to make room for the margins i just dont see where he got his figure of 46.5% seems like a strange number cant find where it comes from will check again ><
Boban Talevski
24,793 PointsYou need to have two of these columns in 100% width, meaning each should be set to 50%. But since we need to consider margins, borders etc. we need to go a bit lower than 50%, which is why I think he chose 46.5%. Could've been 45%, 47%, or any number close to 50 which makes sense and doesn't break the layout.
Bartlomiej Zabielski
Courses Plus Student 10,363 Pointsoooooooooooooooooooooooooooooooooooooooooooooooooooooo thanks all
furkan
11,733 Pointsfurkan
11,733 PointsTo float two items side by side as he does in this video, you must take into consideration the margins and any borders applied to the child elements of a parent container. Then the rest is a bit of Math. For example:
Suppose we created a div container element with a class name of "wrapper" and two child div elements. The parent container element has a width size of 400px. And the two child elements with class name child inside have a size of 180px in width, with 5px margin on the left and right sides and a 1px border. It will look like this in CSS:
By applying a margin to both child elements on their left and right sides, we have a total of 20px margin, because 5+5+5+5 = 20. And a 1px border for each child element = 1 + 1 = 2px in total, and therefore, the margins along with the border added together gives us 22px in total. The child elements now have total width of 180px + 180px + 22px = 382px, and the remaining space left in the parent container is 400 - 382 = 18px. Thus, you will be able to float these child elements side by side since they fit into the parent container.
He used percentages, so you can alternatively convert the child elements width, margin and border property values to a percentage by doing what has been shown above in the code commented out.
To learn more, please visit: https://developer.mozilla.org/en-US/docs/Web/CSS/float