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


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.