Scaling images in HTML with a minimum width/height in HTML/CSS only

孤街浪徒 提交于 2019-12-03 00:47:16

Don't use an <img>. Instead, use a background-image style:

background: transparent url('path/to/image.png') no-repeat scroll center center;
background-size: contain;

The background-size does the magic, scaling the image up or down so that it snugly fits inside the container.

Check out this fiddle http://jsfiddle.net/demchak_alex/FazvX/3/

Though this only works if you can apply classes to individual images

EDIT:

if you can use background images, check out this fiddle http://jsfiddle.net/demchak_alex/FazvX/4/

The "image only with added classes" works on the top, and the using background images works on the bottom.

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