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
.