如何调整到img标签适当? [英] How to resize to the img tag appropriate?

查看:144
本文介绍了如何调整到img标签适当?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在小窗口中显示图像,但我需要保存图像的比例(我仍然希望人们可以知道它是什么)。
例如让我们说图像是1000X200像素,有一个div定义为:
height:100px;
width:100px;
所以我想让图像写成这样:

I want to show an image in small windows but i need to save on the ratio of the image(I still want that people can know what it is). For example lets say that the image is 1000X200 pixels, and there's a div that defined as: height: 100px; width: 100px; So I want that the image will wrote like that:

<img src="asd.jpg" height=20 width=100 />

而不是

<img src="asd.jpg" height=100 width=100 />

<img src="asd.jpg"/>

然后有卷轴..

我可以使用百分比,但是我该怎么做呢?(和单独使用百分比一起工作吗?)

I can work with percentages, but how do I do it.. (and does it even work with percentages alone?)

推荐答案

如果在CSS中设置 max-height max-width ,现代浏览器会将其限制为此大小,长宽比正确:

If you set max-height and max-width in CSS, modern browsers will restrict it to that size but keep the aspect ratio correct:

<img src="asd.jpg" style="max-height: 100px; max-width: 100px;" />

这篇关于如何调整到img标签适当?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆