简体   繁体   English

根据父div大小按比例调整图像大小

[英]Proportionally resize image based on parent div size

I am using full browser width height jquery blockUI to display selected image from gallery. 我使用完整的浏览器宽度高度jquery blockUI来显示从库中选择的图像。 On the image bellow is scheme of view in blockUI. 在图像下面是blockUI中的视图方案。
Basically view in side blockUI has width and height set to 100%. 基本上在侧面块的视图中,宽度和高度设置为100%。
Inside there are two more divs. 里面还有两个div。 Right has width set to 80% of the view and it contain image. 右边的宽度设置为视图的80%,它包含图像。
Image has width and height set to 100% (but this is wrong I know). 图像的宽度和高度设置为100%(但我知道这是错误的)。
Images that I display here are images in original sizes uploaded by users. 我在此处显示的图像是用户上传的原始尺寸的图像。 But if monitor is 1024x768 and uploaded image is 600x1900 I don't what to that image goes out of the screen. 但如果显示器是1024x768并且上传的图像是600x1900,那么我不知道该图像是什么从屏幕上消失。
So how can I fix this to display that image centered and proportional? 那么如何解决这个问题来显示图像居中和比例?

在此输入图像描述

Use max-width and max-height , you will need to use JavaScript in IE 6 if you need to support it: 使用max-widthmax-height ,如果需要支持,则需要在IE 6中使用JavaScript:

#blockUI img {
    max-width: 100%;
    max-height: 100%;
}

This keeps the img element's aspect ratio when resizing, up to the maximum possible width and heights. 这样可以在调整大小时保持img元素的纵横比,最大可能的宽度和高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM