Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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! :(