How to fix flexbox stretching an image rather than retaining the aspect ratio with CSS?

Spread the love

Sometimes, we want to fix flexbox stretching an image rather than retaining the aspect ratio with CSS.

In this article, we’ll look at how to fix flexbox stretching an image rather than retaining the aspect ratio with CSS.

How to fix flexbox stretching an image rather than retaining the aspect ratio with CSS?

To fix flexbox stretching an image rather than retaining the aspect ratio with CSS, we set align-self to center.

For instance, we write

align-self: center;

to stop the element inside the flex container from being stretched.

Conclusion

To fix flexbox stretching an image rather than retaining the aspect ratio with CSS, we set align-self to center.

Leave a Reply

Your email address will not be published. Required fields are marked *