css image auto resize height and width while maintaining aspect ratio

Giving users the power to update their site is a good thing. But sometimes asking a user to resize an image to certain pixel size is a daunting task. So we should always have a container that can resize these images for them. Below is the solution to resize an image based on its maximum height and maximum width while maintaining its aspect ratio. The solution is inspired from addedoptimization. First the image container in the html

Then the css resize code.

 

Submit a Comment