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
budoor ayhd
1,471 Pointswhat the difference between margin:center and margin:auto
what the difference between margin:center and margin:auto
3 Answers
Philip Gales
15,193 PointsYou can read more about text-align at the w3schools.com website.
The text-align property specifies the horizontal alignment of text in an element.
div {
text-align: center;
}
The reason you may want to use margin: auto is if you want to center non-text items.
Say for example you want to center a contact form, you can wrap it in a div and set the margin to auto. The browser will then set each left and right margin to be equal, so the div is centered.
div {
margin: auto;
}
ve
5,048 PointsThere is no such thing as margin: center. Do you mean text-align: center?
If yes, the difference is quite easy: If you have a <div> and give it a margin: auto, you center the <div> itself. If you set its text-align to "center", you center its content, not the <div>.
budoor ayhd
1,471 PointsThanks :)