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 CSS: Cascading Style Sheets Center the Wrapper

Sebastian Eguez
Sebastian Eguez
8,248 Points

Margin and Padding

#wrapper {
    max-width: 940px;
    margin: 0 auto;
    padding: 0 5%;
    background: orange;
}

The video said that the first number ("0" in this case) for both margin and padding affected the top and bottom of the page.

When I change these numbers, the sides are affected.

Why?

Sebastian Eguez
Sebastian Eguez
8,248 Points
#wrapper {
    max-width: 940px;
    margin: 100 5;
    padding: 100 5;
    background: orange;
}

My preview page stays the same. I am saving it.

2 Answers

Brent Suggs
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Brent Suggs
Front End Web Development Techdegree Graduate 21,343 Points

It's because you not using a unit. When using 0 you don't need a unit but anything other than that you need to specify px, % ,em , etc... or it will be ignored.

#wrapper {
max-width: 940px;
margin: 100px 5%;
padding: 100px 5%;
background: orange;
}

When you do:

margin: 10px;

This will affect all sides of the element.

When you do:

margin: 10px 5px;

Now the top and bottom are 10 pixels and the left and right are 5 pixels. It is kind of a shortcut.