I have an image I am displaying in a image tag:
These are thumbnails, but some are a little to wide so for those images I want to force the display to shrink them (even though the larger image is loaded).
How can i do this for images that are larger, while not expanding images t开发者_StackOverflow社区hat are smaller.
You can use CSS properties max-width and max-height on images.
img {
max-width: 300px;
max-height: 200px;
}
works great with all popular browsers, including IE8.
You could add a css class to only those images that exceed a given height or width, then set the height and width in your stylesheet.
You could just specify the height and width attribute of the <img> tag to a value that generally suits most of the images that you are likely to encounter.
精彩评论