[whatwg] <img> element comments

Le 7 nov. 2006 ? 14:28, Greg Kilwein a ?crit :

> Also, if only one of either the "width" or "height" attributes is  
> set, some browsers will scale the other dimension automatically.   
> Consider this example:
>
> <img src="100x50.png" width="50">
>
> Some browsers will scale height to be 25 in this instance, given an  
> image with a width of 100 pixels and a height of 50 pixels.  This  
> is quite useful when the height or width of an image needs to be  
> fixed without distorting the aspect ratio.

You can also do this from a stylehseet in most browsers:

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

although this works only if the height attribute is not present on  
the image. Personally, I often like to use:

    img { max-width: 100%; height: auto; }

but again it doesn't work when the height attribute is set, which is  
somewhat silly if you see this attribute as metadata about the linked  
file while it makes perfect sense if you consider the height  
attribute as the desired height of the image on the page.


Michel Fortin
michel.fortin at michelf.com
http://www.michelf.com/

Received on Wednesday, 8 November 2006 04:40:20 UTC