设置图像的最大尺寸 [英] Set image max size

查看:150
本文介绍了设置图像的最大尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在< img> 标记中设置图片的最大高度和宽度。例如,假设最大尺寸是400x400像素,所以如果图像尺寸小于这个尺寸,那么它会显示图像,如果尺寸较大,那么它应该被压缩到这个尺寸。如何在html或javascript中执行此操作?

解决方案

设置 max-width max-height in CSS

  max-width: 400像素; 
最大高度:400px;


I need to set maximum height and width of a image in <img> tag. For example say max size is 400x400 px so if the image size is smaller than this then it will show the image as it is and if size is bigger then this then it should be compressed to this size. How can I do this in html or javascript?

解决方案

Set the max-width and max-height in CSS

max-width: 400px;
max-height: 400px;

这篇关于设置图像的最大尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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