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!
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
Pitrov Secondary5,121 Points
What is the difference between text-align: center; and margin: auto;?
When he said to take text-align to center. I thought why not margin to auto, and what would be the consequences to that. when do I use margin: auto; instead of text-align: center;.
Steven Parker228,119 Points
These are both centering techniques, but they work on different kinds of elements. For a full-width block element, such as a heading or div, the margin setting would have no effect but the text-align would work.
On the other hand, if you change the display mode to "table", then text-align would do nothing but the margin would be effective.
As khay sing pointed out, this relates to whether you are affecting the position of the element itself or the contents. Try some experiments after adding a border to the element to make the difference obvious.