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 How to Make a Website Styling Web Pages and Navigation Build Navigation with Unordered Lists

Why do you have to add a margin to the right and left of nav? Why does it not work only with setting padding to 0?

It make more sense to me only to set the padding to 0. Why do we have to set the margin left and right to 10 px?

Why does it not work if I set the padding to 0 and all margins to 0? When I do that the ul does not get centered. It works only when we add the margin left and right as the videos suggests.

1 Answer

This is a pretty handy explanation of margin: auto and why you often see margin: 0 auto used for centering. http://learnlayout.com/margin-auto.html

Thanks, but I meant the margin applied to nav ul though. After he centers the nav there is still a little indentation to the right and the way he fixes it is with:

nav ul { list-style:none; margin: 0 10px; padding: 0; }

The thing I do not understand is why he adds a margin of 10px left and right?