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


7,823 Points

Does margin: auto; not center things perfectly?

I'm making a mobile version of a site on I'm making a gallery that isn't float, so the images are stacked on top of one another. When I set the width of the image's li container to 80% or less it looks mostly centered, however when I set the width to 90% or more the image isn't center all the way and is more one the left. Is this normal?

Your post is confusing. If you are setting a width in percentage on your li tag that will work in relation to its parent element, probably a ul tag - that has no effect in centering an element. You mention "margin: auto" in the title of the post but don't elaborate on that, maybe sharing the code using a service like codepen.io or jsfiddle.net would be better.

1 Answer

Tom Checkley
Tom Checkley
25,165 Points

ul's have a padding value, you need to set

ul {
  padding: 0;