Is there a way to add an in-line image using HTML that is responsive but has a max width?
I know that I can use <img width="100%" />
to make it responsive, but this results in the image resizing to the container size, and I want to set a max width/size for it.
Is this possible? The reason I don't want to do it using CSS is because in this instance I can't edit the master/parent CSS and would rather not use in-line CSS.
Thanks.
If you are not looking to set the percentage, then use this:
<img style="max-width: 200px;">
However I like to set it like this:
<img style="max-width: calc(100% - 20px);">
this way you can set the img to certain px smaller than its container. either one will work.
My most common need for intelligently choosing width would be to size something to 100% unless that gets too big. For example, specify both width and max-width:
<img src="myimage.png" style="max-width:1000px; width:100%;">
That is inline-CSS, which the original question states is not desired; however, the OP then chose a solution which was inline CSS.
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