tags:

views:

1933

answers:

4

Is there a way to resize (scale down) images proportionally using ONLY CSS?

I'm doing the JavaScript way, but just trying to see if this is possible with CSS.

A: 
<img style='width: 50%;' src="..." />

worked just fine for me ... Or am I missing something?

Edit: But see Shawn's caveat about accidentally upsizing.

Adrien
sorry, I like to separate the content and design of a site.I totally know that adding width rule works fine, which I originally had. Thanks :)
bLee
+1  A: 

The css properties max-width and max-height work great, but aren't supported by IE6 and I believe IE7. You would want to use this over height / width so you don't accidentally scale an image up. You would just want to limit the maximum height/width proportionately.

Shawn Simon
This seems to be the best way when targeting HTML5-capable browsers.
Nestor
+3  A: 

Ethan Marcotte recently investigated this issue very thoroughly. The short answer is yes, it's possible, but not in all browsers.

Mark Hurd
I'm not sure you're answering the question. `max-width` isn't the problem, it's that when you use it, the aspect ratio of the image isn't maintained.
Samir Talwar
@Samir - If you read the article, you will see his test cases using max-width do in fact proportionally resize the image as the OP requested. The quality is terrible in IE though, and requires JavaScript support to fix, unfortunately.
Mark Hurd
You're right. Which is odd, because my tests show otherwise. Perhaps I'm doing it wrong... shall experiment further.
Samir Talwar
A: 

To resize the image proportionally using CSS I tried following.

img.resize{
    width:540px; /* you can use % */
    height: auto;
}
Mkk