I have a div with a defined width and height. Then I have an image which I want to fit on it (keeping proportions). Like that JsFiddle :
<div style="width: 200px; height: 300px; background: red;">
<img src="http://placehold.it/200x800" style="width: auto; height: auto; max-width: 100%; max-height: 100%" />
</div>
Now I want a div wrapped on the img (that is ajusted exactly to the img width and height and position) because then want to have some elements inside the div with position:absolute
relatively to the img. Check on JsFiddle:
<div style="width: 200px; height: 300px; background: red;">
<div style="display: inline-block; max-width: 100%; max-height: 100%; background: blue;">
<img src="http://placehold.it/200x800" style="width: auto; height: auto; max-width: inherit; max-height: inherit" />
</div>
</div>
The result is wrong, cause the img is overlayed on the div. I want the img to resize like in the first example.
In Child with max-height: 100% overflows parent they pointed out that the div needs to have a height and a width, but then the div will not be filling the whole img.
There is actually a way to do it?
My whole layout is more complex and totally responsive with flex on top and the example here is just an approximation focused on the issue I have. So any solution with fixed height and width will be wrong.