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 trialHerbert Showalter
1,514 PointsHow do I get my Nav links to center and to display inline-block?
nav { display: inline-block; }
nav { text-align: center; padding: 10px 0px; margin: 20px 0 0;
}
nav li { list-style: none; margin: 0 10px; padding: 0; }
nav { font-weight: 800; padding: 15px 10px; }
With this code entered, I still cannot get my nav links to center and inline-block on my portfolio page. Insight please.
2 Answers
Sam Baines
4,315 PointsHi Herbert - try using the value 'auto' for the margin left and right, like below:
nav li {
margin: 0px auto;
}
That will automatically set the left and right margins to the overall width of the parent element - thus it should automatically centre your nav links. Have a play around with this Codepen I put together to show you the changes.
Yaroslav Kleshchev
8,744 PointsAdd a margin of auto the the left and right of the element.
nav li { margin-left: auto; margin-right: auto: }