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

HTML How to Make a Website Styling Web Pages and Navigation Style the Portfolio

Farid Wilhelm Zimmermann
Farid Wilhelm Zimmermann
16,753 Points

I dont understand why he uses the margin, only for the left and right values?

In the How to Make Website video Nick talks about setting up the image gallery using a css-rule containing the float property with the value left. He gives the list elements a width of 45 % (times 2 elements equals to 90% total width). After that he continues to set the margin for the list elements to 2,5%. His css declaration is " margin: 2,5% ".

Why does this only set the margin for left and right? Why wouldnt that set the margin for all four sides of the element? Previously we learnt that if you want to set a margin for example for the top and the bottom, you would declare(e.g. margin: 10px 0px;) would set set the margin-top and margin-bottom to 10px, while left and right would remain at 0px. Why doesnt he declare "margin: 0% 2,5%;" in his css-rule to only affect the left and the right of the working elements?

1 Answer

Steven Parker
Steven Parker
231,269 Points

A single margin setting does set the margins on all sides. In the commentary, he's focusing on how the horizontal margins are working on concert with the width settings to use the available space.

The vertical components of the margin setting are just not mentioned.