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 trialIngrid Bardales
10,616 Pointstrying 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
Jason Anello
Courses Plus Student 94,610 PointsHi 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
10,616 PointsThank 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
18,837 PointsGlad 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
10,616 PointsThank you Mousa, for stopping by also!
Ingrid Bardales
10,616 PointsIngrid Bardales
10,616 PointsThank you Jason ok i got it. Just one question..I am having a hard time understanding "auto" how does this work? Thanx a million!
Mousa Alqarni
22,619 PointsMousa Alqarni
22,619 Pointsgood 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
18,837 PointsGuy Noda-Bailey
18,837 PointsThe auto part centers the element by auto*magic*aly, making the margins on the left and right the same amount.