views:

98

answers:

2

Hi. I’m trying to get an image (dynamically placed, with no restrictions on dimensions) to be as wide as its parent div, but only as long as that width isn’t wider than its own width at 100%. I’ve tried this, to no avail:

img {
    width: 100%;
    height: auto;
    max-width: 100%;
}

Many of these images are way wider than their parent div, which is why I’d like them to resize accordingly, but when a small image pops in there and gets scaled up beyond its normal dimensions, it really looks terrible. Is there any way of doing this?

+4  A: 

Just specify max-width: 100% alone, that should do it.

Fyodor Soikin
Chromium seems to simply leave it at 100% regardless of context. Perhaps I should stop constantly looking at my work on beta software. Thank you!
Alfonso
A: 

For a max-width that also works on Internet Explorer, you might have to do something like this:

width: auto !important; /*override the width below*/
width: 100%;
max-width: 100%;
jwal