Can anyone help me with writing an img
tag for images of varying sizes? I'm looking to scale down larger images to fit the container at width: 100%
, but I do not want smaller images to be scaled up. I want them to maintain their natural size when viewed on a larger screen.
Here's what I've attempted so far:
causes overflow for large images in the container.<img src='image.jpg' alt='image'>
scales down large images correctly, but enlarges small ones which is unwanted.<img src='image.jpg' alt='image' style='width:100%;'>
- In Chrome,
works well by scaling down large images and keeping small ones unchanged. However, this doesn't always work as expected in other browsers.<img src='image.jpg' alt='image' style='max-width:100%;'>
EDIT
I should mention that my container width is not fixed. It adjusts along with the window size and adjacent elements.