How to get image to fit in div (don't go beyond it) and keep it's aspect ratio while never having more than 150px
in height
?
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="border: 1px solid black; height: 200px; width: 200px;">
<img src="https://about.canva.com/wp-content/uploads/sites/3/2017/02/congratulations_-banner.png" style="max-height: 150px; width: auto;" />
</div>
</body>
</html>
As you can see here image width
is auto
and max-height
is 150px
although this image goes beyond parent div and his borders.
How to make this image keep it's aspect ratio and fit in this div and scale down but also having max-height
of 150px
. So never height is more than 150px
and width
is auto
to this height
to keep it's ascpet ratio and also fit in this div.