The power with scaling images is immense but very few people use it on a website. Scalable images are set in either ems or percentages.
For images that you know the width and height of, you can set the dimensions so that the image is not distorted:
img.widescreen {
width: 16em;
height: 9em;
}
For unknown image sizes, one side must be set to auto — this will force the correct aspect ratio upon the image, avoiding any skewness:
img.scale {
height: auto;
width: 75%;
}
Scaling images are great because you can prevent them from ruining your layout by going over an edge. If they are set in percentages and have limitations, it also means that they won’t go larger than the boundaries of the page and still remain undistorted, even when the browser is resized:
img.scale {
height: auto;
max-width: 100%;
width: 30em;
}
Using the max-width/max-height property, you can also prevent everyday images from ruining your layout as well.
Comments
1 response has been made so far. Add your comments.
Hey Sid,
After reading the first line I was about to surf away… Scaling images can be powerful for both good AND evil. I’m sure everyones seen images stretched way beyond their normal size, or skewed from a bad aspect ratio…
I did not know about the max-width css tag though! I may not be so fearful of scaling in the future.