Reputation: 12151
Is there a way to have an IMG resize it's width (and height to maintain aspect ratio) relative to the containing DIV?
Use Case This is for an email newsletter, so I can't use .js There is a containing div that resizes based on the page width. I want the IMG in it to "obey" that.
I've tried just setting Style="Width:100%" but that doesn't work.
Upvotes: 0
Views: 58
Reputation: 221
Did you try it as an attribute, width="100%" ? That should make it work across the board. Height should auto-adjust.
Upvotes: 0
Reputation: 21789
If you need to use inline-styles:
<img style="width: 100%; height: auto;" src="..." />
Upvotes: 0
Reputation: 1957
img {
max-width:100%;
height:auto;
}
Setting the height
to auto
is only necessary if a width and height attribute were set in the image tag.
http://jsfiddle.net/e2003kac/1/
Upvotes: 2