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 CSS: Cascading Style Sheets Review: CSS: Cascading Style Sheets

Radu Zurbau
Radu Zurbau
501 Points

I still do not understand what the "auto" property does in CSS (margin). Why haven't we used auto for the #logo as well?

Why do we use the "auto" property to set a section centered. Why not a "center" property for instance. What does this property actually do? It obviously centers the section on the page but why? What does "auto" tell the browser?

Also why haven't we used the "auto" property when defining the "margin" for #logo as well?

Thank you

2 Answers

Harry Beckwith
Harry Beckwith
13,452 Points

Margin auto will horizontally center an element inside of its container.

For example

.center { margin: auto; width: 60%; border:3px solid #8AC007; padding: 10px; }

Would align .center into the middle. In this example it is the same as adding 15% margins left and right of the div to center it.

Check out this link as well......

http://www.w3schools.com/css/tryit.asp?filename=trycss_align_container