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

How to center a list into his parent without using margin or padding.

Hi, I only want to center the list into the nav

HTML:

  • nav1
  • nav2
  • nav3

CSS (colors only used to identify the elements):

body { width: 960px; margin: auto; background-color: tomato; }

nav { background-color: lightblue; }

li { list-style: none; display: inline-block; font-size: 2em; position: relative; left: 320px; }

I don't think that it is the right way.

5 Answers

Did you try text-align: center ?

sure but it doesn't works. LI is the child of UL so, first I centered the UL next I tried to center the LI into UL. But nothing....

I'm a little confused as to what you are after. Is it something like this?

http://codepen.io/seraphzz/pen/GqFCv

great thank you. I don't know why I was trying to center the LI element.

I've spent hours trying to figure out the same problem - thank you for posting this!!!