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.


jay-lewis read
jay-lewis read
1,105 Points


Good afternoon.

Basically, I'm attempting to create a mock website and I'm having a few difficulties regarding images.

I have four images that are currently sitting as follows Image1 Image2 Image3 Image4 Basically I wish to display these images in a line, and center them at the same time. Something like this Image1 image2 image3 image4

I'd appreciate any help that could be offered.

1 Answer

Saleh Ben Nakhi
Saleh Ben Nakhi
7,305 Points

you can do that by changing a few things in CSS. each line is 100% its own width, so the sum of widths of all of your images should'nt exceed 100%, giving each 25% width would make them fit, but going for a smaller value e.g. 20% would give the images more space to breath.

make sure they display as inline-block set the margin to auto and that should solve the problem. you can target all images at once using the img selector

img { width: 20%; display: inline-block; margin: 0 auto; }

I hope this helps.