Categories
CSS

How to auto-resize an image to fit a div container with CSS?

Spread the love

Sometimes, we want to auto-resize an image to fit a div container with CSS

In this article, we’ll look at how to auto-resize an image to fit a div container with CSS.

How to auto-resize an image to fit a div container with CSS?

To auto-resize an image to fit a div container with CSS, we set the max-width and max-height properties.

For instance, we write

img {
  max-width: 100%;
  max-height: 100%;
}

to set the max-width and max-height to fill the whole container’s dimension if it doesn’t change the aspect ratio .

Conclusion

To auto-resize an image to fit a div container with CSS, we set the max-width and max-height properties.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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