How to proportionally size images to fit dimensions of 200px x 150px thumbnail in css?

拟墨画扇 提交于 2020-01-04 05:27:17

问题


I`ve tried a couple of things even using the CSS clip, but not getting it proportionally fit in the thumbnails here http://giantmango.com/arttest2-2510.

In CSS, what is the best way and how would I proportionally resize an image to display in dimensions of a 200px (width) x 150 (height) thumbnail?

Just checked firebug and for some reason all my img tags are always set to a height of 200 even though I have max-height set to 150...


回答1:


Use max-height and max-width. Beware that they are broken in older versions of IE. You can do

#myImage: {
    max-height: 150px;
    max-width: 200px;
}

EDIT: @tokiowp: try this. It should work (it surely does for me). So the problem with your layout comes from additional properties you may have set.

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <img style="max-height: 150px; max-width: 200px" src="giantmango48.jpg" />
    </body>
</html>

EDIT: it turns out, looking at your source, that you are actually declaring your images with something like

<img src="http://giantmango.com/wp-content/uploads/giantmango78.jpg" alt="" title="giantmango78"  width="200" height="200"/>

Of course what you need is to remove these declarations of width and height.




回答2:


css:

#thumb {width:200px; height:150px;}
#thumb img {height:100%; width:100%; margin:0 auto;}

html:

<div id="thumb"><img src="tb01.jpg"></div>


来源:https://stackoverflow.com/questions/5057516/how-to-proportionally-size-images-to-fit-dimensions-of-200px-x-150px-thumbnail-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!