Why does flexbox stretch my image rather than retaining aspect ratio?

sjbuysse picture sjbuysse · Jun 3, 2016 · Viewed 104.4k times · Source

Flexbox has this behaviour where it stretches images to their natural height. In other words, if I have a flexbox container with a child image, and I resize the width of that image, the height doesn't resize at all and the image gets stretched.

What causes this?

I added This CodePen to demonstrate what I mean.

Answer

pradeep1991singh picture pradeep1991singh · Jun 3, 2016

It is stretching because align-self default value is stretch. Set align-self to center.

align-self: center;

See documentation here: align-self