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

Centering Navigation inside Header

When asked to center the navigation element inside the header I wrote: nav { text-align: center; display: inline-block; } However, this had no effect on the appearance of my page when I checked it. When I applied the "text-align: center;" to the header element instead after watching your example, the whole header suddenly centered. Why didn't it center when written under the "nav" selector?

Thank you!

1 Answer

The text-align property only centers text . I suggest you use margin: auto which center block of element like head,div and nav. Hope that helps

Thank you for your answer. I did try using "nav { margin: center; } " to center the navigation list, but that also had no effect. And the nav element is nested within the header element. It only worked when I wrote " header { text-align: center; } nav { display: inline-block;} " and this centered the navigation list under the main header and logo of the page.
I was just curious why only this way has worked and the other ways that I thought would work didn't.