简体   繁体   English

最大高度流畅的图像响应功能不适用于Chrome,Firefox等,但适用于Safari

[英]Max-height fluid image responsive doesn't work in Chrome, Firefox etc. but works in Safari

I'm trying to accomplish image resizing for height (I'm aware of width:100%, height:auto for width resizing). 我正在尝试完成图像的高度调整(我知道width:100%,height:auto来调整宽度)。 The below setup works in Safari (~8.02) but Chrome and Firefox (latest) don't care at all. 以下设置可在Safari(〜8.02)中使用,但Chrome和Firefox(最新)完全不在乎。 Any ideas? 有任何想法吗? If no CSS hacks exist, I'm open to jQuery solutions (I guess). 如果没有CSS hacks,我愿意接受jQuery解决方案。

 body, html { width:100%; height:100%; } body { background: lightgreen; } .full { width:100%; } .block { background: lightcoral; width: 80%; text-align: center; position: absolute; } .logo { max-width: 100%; max-height: 80%; } 
 <div class="full"> <div class="block"> <img src="http://placehold.it/709x534" class="logo"> </div> </div> 

In addition to the CSS above, declaring a height of 100% on the container (in this case, .block) resolved the issue on Chrome and Firefox. 除了上述CSS外,在容器上声明高度为100%(在这种情况下为.block)可以解决Chrome和Firefox上的问题。 It now matches Safari behavior as intended. 现在,它符合预期的Safari行为。

Are you trying to purposely distort your image after it goes beyond an 80% height? 在图像高度超过80%之后,您是否要故意使图像失真? Check out this post... Max-height ignored in Firefox, works in Chrome and Safari 看看这篇文章... Firefox中忽略的最大高度,可在Chrome和Safari中使用

In addition to the CSS above, declaring a height of 100% on the container (in this case, .block) resolved the issue on Chrome and Firefox. 除了上述CSS外,在容器上声明高度为100%(在这种情况下为.block)可以解决Chrome和Firefox上的问题。 It now matches Safari behavior as intended: 现在,它符合预期的Safari行为:

 body, html { width:100%; height:100%; } body { background: lightgreen; } .full { width:100%; } .block { background: lightcoral; width: 80%; text-align: center; position: absolute; height: 100%; } .logo { max-width: 100%; max-height: 80%; } 
 <div class="full"> <div class="block"> <img src="http://placehold.it/709x534" class="logo"> </div> </div> 

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

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