Is there a way to set the max-width of images on a website with CSS without knowing their actual width?
Currently, my CSS includes:
img {width: 100%; height: auto; display: block;}
This code ensures that all images will fill the full width of the browser and adapt when the browser window is resized.
My concern is how to determine the width of an image uploaded through a CMS like Wordpress so that I can set a max-width for it in order to prevent stretching without using a generic value in the CSS. Is this achievable with pure CSS or would I need to utilize JavaScript?
I am uncertain about the dimensions of images that users may upload or update on their site.
In previous cases, I have specified a max-width value within a specific class (for example):
.post img {max-width: 300px;}
This approach worked well when I knew the widths of the images beforehand. However, now that I am unsure of the images' widths, I am seeking a solution to dynamically set the max-width based on the uploaded images.