Sometimes, we want to auto-resize an image to fit a div container with CSS
We’ll look at how to auto-resize an image to fit a div container with CSS, in this article.
How to auto-resize an image to fit a div container with CSS?
First we have to set the max-width and max-height properties, to auto-resize an image to fit a div container with CSS.
For instance, we can write
img {
max-width: 100%;
max-height: 100%;
}
Fill the whole containers dimension, to set the max-width and max-height if it doesn’t change the aspect ratio .
Conclusion
Then set the max-width and max-height properties , to auto-resize an image to fit a div container with CSS.