Clay Nichols
Clay Nichols

Reputation: 12151

Set IMG.width to resize to container (DIV, etc.) width without .js

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

Answers (4)

Geoff Phillips
Geoff Phillips

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

taxicala
taxicala

Reputation: 21789

If you need to use inline-styles:

<img style="width: 100%; height: auto;" src="..." />

Upvotes: 0

Tom Nolan
Tom Nolan

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

Luc Laverdure
Luc Laverdure

Reputation: 1480

style="max-width:100%;width:100%;"

Upvotes: 0

Related Questions