How can I add an image to an HTML page using the following constraints:
For instance I have an image (400x300). If the containing element is 600 pixels wide I'd like to show the image at 400x300. If the containing element is 200 pixels wide ( for instance it's a mobile browser ) I'd like to show the image at 200x150.
I'm looking for a pure CSS solution (if it's possible) without hard wiring the image size.
Using the max-width property twice works correctly:
<div style="max-width: 400px" >
<img src="image.jpg" style="max-width:100%;" />
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With