When using an image with max-width in a flex item, the flex item grows more than it should. My expected result is the flex item being as wide as the image. Why this is happening and how can be fixed?
A minimal example of the issue: https://jsfiddle.net/kpy4nra7/
HTML:
<div class='flex'>
<div>hello</div>
<div>hello world</div>
<div>
<img src="https://via.placeholder.com/400x100">
</div>
</div>
CSS:
.flex {
display: flex;
flex-direction: column;
border: 1px solid red;
align-items: flex-start;
}
.flex div {
background:pink;
}
.flex img {
max-width: 50%;
}