Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!