Reputation: 15695
Is there any way that I can use just HMTL and CSS to force an image to resize to fit a fixed dimension while maintaining its aspect ratio (without stretching/shrinking)?
Consider my required dimension to be a 64x64 pixel square, and the following cases for images I want to fit within this dimension:
I've been able to figure out a way to solve either 1 & 2 or 1 & 3 by explicitly declaring the image's height="64px"
and width="64px"
respectively, but one does not work for both, and declaring both causes the image to stretch or shrink.
Is there a way to solve this problem only using HTML and CSS?
Upvotes: 2
Views: 948
Reputation: 5290
use max-width and max-height instead. don't set width/height in css.
style="max-width: 64px; max-height: 64px;"
Upvotes: 3