I'm creating a gallery where I want to list all images from an album on one page : Big Picture style :
Unlike Big Picture, I want the images to proportionally scale to fit to the width of the container div
(.section-images
, which is set to margin: auto 2em;
so its width is the width of the user's browser minus 2*2em
) as much as possible without making them larger than 90% height of the viewport.
As you imagine, a 400x600
portrait photo when scaled to fit the width would be so long the user would not see the whole image on screen, thats why I need to limit width scaling to not exceed 90% height.
<section class="section-images">
<div class="image-box">
<div class="image-large">
<a href="#"><img foo1></a>
</div>
<div class="image-description">
blabla1
</div>
... MORE IMAGES WITH DESCRIPTONS ...
</div>
etc
</section>
Under each image I have the .image-description
, the height of this will vary.
What is important is that at any one time a single image (so .image-large
) should fit in the viewport, regardless of whether it is landscape or portrait.
I would like to do this using only CSS if possible, and only javascript if CSS is not possible.