Alex Rivera | Logout

How to resize to the img tag appropriate?

Asked 2011-04-21T19:05:55.367
26

I want to show an image in small windows but i need to save on the ratio of the image(I still want that people can know what it is). For example lets say that the image is 1000X200 pixels, and there's a div that defined as: height: 100px; width: 100px; So I want that the image will wrote like that:

<img src="asd.jpg" height=20 width=100 />

and not

<img src="asd.jpg" height=100 width=100 />

or not

<img src="asd.jpg"/>

and then there's scrolls..

I can work with percentages, but how do I do it.. (and does it even work with percentages alone?)

Edit
Report

1 Answer

58

If you set max-height and max-width in CSS, modern browsers will restrict it to that size but keep the aspect ratio correct:

<img src="asd.jpg" style="max-height: 100px; max-width: 100px;" />
answered 2011-04-21T19:09:59.800

Your Answer