InfoStatus
InfoStatus

Reputation: 7113

HTML Display an Resized Image maintaning Ratio

I want to show an image from a URL and I want that image to have a given size but I want to maintain the ratio between height and width.

Upvotes: 1

Views: 473

Answers (3)

Mike Robinson
Mike Robinson

Reputation: 25159

CSS:

img {
 width: 30%;
 height: auto;
}

Something like this?

Upvotes: 5

Ian G
Ian G

Reputation: 30234

you can use css to style an image

i believe if you use px for example, and specify only one dimension

img {width:100px}

the ratio is usually maintained

You can use

img {width:100px;height:auto;}

which may help

if you use

img {width:100px} 

the ratio is maintained in IE 7 at least

Upvotes: 0

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114367

<img src="http://..." height="100" />

No magic here, although client-side resizing usually looks crappy.

Upvotes: 2

Related Questions