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

General Discussion

centering 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

Try margin 0 auto or text-align: center

Hi 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.

I'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.

Hi, 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.