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

Amanda Bater
Amanda Bater
7,686 Points

Why is margin:auto not centering my gallery items?

Practising what I've learned by doing a personal project...designing a website with a gallery, and for mobile view I'd like the gallery items to be in one column that is centered in the middle of the browser window.

I've tried selecting the .gallery and applying margin:auto, but it hasn't worked. Why could this be?

Link to code snapshot: https://w.trhou.se/3apjtrvdt3

4 Answers

You are right, I meant to paste in this:

.gallery {
    margin: auto;
    width: 60%;
}

The width needs to be something less than 100%.

Sorry about that.

Amanda, usually the reason is that you have the width at 100%. Try something like this instead:

.gallery {
    margin: auto;
    width: 100%;
}
Amanda Bater
Amanda Bater
7,686 Points

Hi jcorum. Unfortunately that hasn't worked! :(