The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › CSS › set image to 100% unless container wider than image
Can you set an image to fill 100% of a container’s width except when the container’s width exceeds the image’s natural width?
I find the distortion of the enlarged image more noticeble than the shrunken image.
You should be able to do this by applying max-width:100%; to the img element.
max-width:100%;
You can do that just to set the width of the image 100% and it will follow the container.
Like that img{width: 100%};
img{width: 100%};