In this example the "SQUARE" image is 225x225. When its height is scaled to fit the yellow flex container, Chrome maintains its aspect ratio but Safari does not. (Codepen)
Is there a (pure CSS) way to make it work in Safari? (The image size must continue to depend on its parent's height.)
Correct (Chrome):
Incorrect (Safari):
#green {
display: flex;
height: 200px;
width: 300px;
padding: 20px;
background: green;
}
#blue {
flex-grow: 1;
background: blue;
}
#yellow {
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 20px;
background: yellow;
}
img {
height: 45%;
}
<div id="green">
<div id="blue"></div>
<div id="yellow">
<img src="https://drive.google.com/uc?export=view&id=1SrFS5yT4nJZgzVgWzFYtyjHLeqsyJLtF"/>
<img src="https://drive.google.com/uc?export=view&id=1SrFS5yT4nJZgzVgWzFYtyjHLeqsyJLtF"/>
</div>
</div>
These ideas didn't work: aspect-ratio: 1 / 1
, object-fit: scale-down
(from this question); align-items: flex-start
, object-fit: contain
(from this question).