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 How to Make a Website Styling Web Pages and Navigation Style the Portfolio

Using pictures of different orientations/sizes to fit together like a puzzle

Not all of the photos i'm putting in my gallery are of the same orientation. Using the float leaves a big space in between the images if there is a portrait on one side and landscape on the other. Is there anyway to structure the gallery so that the images fit closer together (like a puzzle)?

2 Answers

Kevin Korte
Kevin Korte
28,149 Points

3 options i can think of:

  • Use CSS flex box layout. Flexbox can handle this sort of thing better than floats. Problem is flexbox is still relatively new, and browser support is catching up.
  • Use a JS plugin like Masonry.
  • Use CSS to resize and crop the images so they are the same size. This probably isn't the desired solution, but it's probably the easiest.

Thanks so much James. I like the idea of using CSS with Masonry as a fall back. You guys are the best.