Resizing image while maintaining aspect ratio

A

Andrew Poulos

My page opens in a new window at a predetermined size so I can set the
relative size of an image in the page to maintain its correct aspect
ratio. When the user resize the window the page's content are resized
accordingly (as they are sized proportionally).

What happens though is that a square image can end up as a long thin
rectangle. How can I code it so that the image's aspect ratio is maintained?

Andrew Poulos
 
E

Evertjan.

Andrew Poulos wrote on 31 mrt 2009 in comp.lang.javascript:
My page opens in a new window at a predetermined size so I can set the
relative size of an image in the page to maintain its correct aspect
ratio. When the user resize the window the page's content are resized
accordingly (as they are sized proportionally).

What happens though is that a square image can end up as a long thin
rectangle. How can I code it so that the image's aspect ratio is
maintained?

Show your javasascript code [please only the relevant part],
ad we can comment on the flaw.

However, you do not need javascript, css style will be enough.
 
T

Thomas 'PointedEars' Lahn

Andrew said:
My page opens in a new window at a predetermined size so I can set the
relative size of an image in the page to maintain its correct aspect
ratio. When the user resize the window the page's content are resized
accordingly (as they are sized proportionally).

What happens though is that a square image can end up as a long thin
rectangle. How can I code it so that the image's aspect ratio is maintained?

Use CSS:

img {
width: 100%;
}

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top