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
pgmd
6,897 Pointscentering elements
This is not centering on the page: Also, the font does not adjust down with screen size. Thank you!!
h2 { font-family: Arial, bold, sans-serif; font-size:1.25em; margin-left: auto; margin-right: auto; }
3 Answers
Diane Houghton
5,773 PointsTry margin 0 auto or text-align: center
Devin Gray
39,261 PointsI'd say make sure the the padding and margin should maybe be set to 0, I understanding liking to code in the longer format but it's still not best practice if you work for a company. Also if all else fails you can go to the HTML and align="center" the h2 element.
Also it helps if you have some type of reset.css or normalize.css to remove the browser's default styling.
Diane Houghton
5,773 PointsHi, it's not the same - I'm setting the top margin to 0, and the left and right to auto. It solves a lot of problems to get rid of that top margin.
pgmd
6,897 Pointspgmd
6,897 PointsHi Diane, Thank you for the answer. The a tile, it seems that text-align: center does not center it exactly (could be some padding or margin inherent to h tags). Also margin: 0 auto is the same as margin-right: auto and margin-left: auto. I just have a preference when centering to use the longer coding format. Thanks again.