I have a scenario in which images of varying dimensions appear in a column that's 50% page width.
On large screens where the column width exceeds an image's native width, the image should render to its native width while still being fluid.
Image dimensions vary (i.e. landscape vs. portrait orientation), so no single width or height can be applied to the img element. I can constrain parent element to a max-width that matches the largest image width that will display, but images of lesser widths expand too wide once made fluid.
The basic structure is:
<div class="column">
<figure>
<img>
</figure>
</div>
With this CSS:
.column {width:50%;}
.column figure {
display:block;
margin:0 auto;
width:100%;
max-width:800px; /* the largest image width */
text-align: center; /* to center images of lesser width */
}
.column img {?}
I can add a data attribute to the img element indicating orientation, using this to apply max-width, but this requires more work for site editors, which I need to avoid. Hence, I seek a CSS-only solution...but I'm stuck.
Any ideas?