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

JavaScript

resizing images for gallery??

So i have a gallery set up, where you click thumbnails and a larger version of the picture appears in a div to the right.

The size of the div is 500px wide, 400px high. All my images are different sizes, also some are landscape some are potrait.

What I'm looking for is someway to scale down these so that they fight inside the div but don't lose there aspect ratio.

Any ideas?????

1 Answer

Get width and height ratio: 500px/width of image and 400px/height of image and there will be a choice: get the max or min ratio. The first one will "crop" image like CSS property "cover" and the second one like "contain". You can see it here. Play it and choose one you prefer:

"Property Values" section http://www.w3schools.com/cssref/css3_pr_background-size.asp