I am using an img tag of HTML to show a photo in our application. I have set both its height and width attribute to 64. I need to show any image resolution (e.g. 256x256, 10
Wrap the image in a div
with dimensions 64x64 and set width: inherit
to the image:
<div style="width: 64px; height: 64px;">
<img src="Runtime path" style="width: inherit" />
</div>
Don't set height AND width. Use one or the other and the correct aspect ratio will be maintained.
.widthSet {
max-width: 64px;
}
.heightSet {
max-height: 64px;
}
<img src="http://placehold.it/200x250" />
<img src="http://placehold.it/200x250" width="64" />
<img src="http://placehold.it/200x250" height="64" />
<img src="http://placehold.it/200x250" class="widthSet" />
<img src="http://placehold.it/200x250" class="heightSet" />
With css:
.img {
display:table-cell;
max-width:...px;
max-height:...px;
width:100%;
}
Use object-fit: contain
in css of html element img
.
ex:
img {
...
object-fit: contain
...
}