Sunday, March 27, 2011

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.

From stackoverflow
  • CSS:

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

    Something like this?

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

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

  • 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

0 comments:

Post a Comment