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 Adding Pages to a Website Style New Pages

Ingrid Bardales
Ingrid Bardales
10,616 Points

trying to understand margin: 0 auto 30px;

I understand 'margin: 0 auto' centers but why in this example is 30px added?

profile-photo { display: block; max-width: 150px; margin: 0 auto 30px; border-radius: 100% }

3 Answers

Hi Ingrid,

When you specify 3 values for margin the 1st value is for the top margin, the 2nd value is for the left and right margin, and the 3rd value is for the bottom margin.

So in this case Nick simply wanted to have 30px of margin below the profile photo. Had he used 0 auto then both the top and bottom margin would be 0.

Ingrid Bardales
Ingrid Bardales
10,616 Points

Thank you Jason ok i got it. Just one question..I am having a hard time understanding "auto" how does this work? Thanx a million!

good my friend you got point for that . i know about that but i am happy we are helping others to improve for better .

Guy Noda-Bailey
Guy Noda-Bailey
18,837 Points

The auto part centers the element by auto*magic*aly, making the margins on the left and right the same amount.

Ingrid Bardales
Ingrid Bardales
10,616 Points

Thank you Guy, now i get it, it was driving me crazy. I would center stuff buy didn't understand the logic behind the 'auto' syntax.

Guy Noda-Bailey
Guy Noda-Bailey
18,837 Points

Glad the forums could help. I always find it so much easier to remember stuff when I understand why it works as opposed to just what to type.

Ingrid Bardales
Ingrid Bardales
10,616 Points

Thank you Mousa, for stopping by also!