简体   繁体   English

Chrome与Firefox的最大高度图像

[英]Chrome vs Firefox for images with max-height

Take this code and open it in Firefox and in Chrome: 获取以下代码,然后在Firefox和Chrome中打开它:

 html, body { margin: 0; padding: 0; height: 100%; } .container { background: #EEE; width: 100%; height: 300px; ; } img { display: block; max-width: 100%; height: auto; max-height: 300px; } 
 <div class="container"> <img src="http://curiosidades.batanga.com/sites/curiosidades.batanga.com/files/Los-gatos-nos-ignoran-1.jpg" alt="" /> </div> 

You have to reescale the width of the container by (for example) reescaling the frame or the browser window (this may help: http://codepen.io/vandervals/pen/NqvYQZ ) 您必须通过(例如)重新缩放框架或浏览器窗口来重新缩放容器的宽度(这可能会有所帮助: http ://codepen.io/vandervals/pen/NqvYQZ)

You'll see the difference inmediatly: Chrome uses the max-height and the max-width at the same time for limiting the scale of the picture, while firefox, only uses the max-height . 您会立即看到差异:Chrome会同时使用max-heightmax-width来限制图片的比例,而firefox只使用max-height

Does anyone know how to make firefox behave like chrome? 有谁知道如何使Firefox表现得像铬? Which of the behaviours is the correct one, according to the spec? 根据规范,哪种行为是正确的?

Use firefox specific CSS, witht he code -moz Another solution would be to use hacks Browser Hack 使用特定于Firefox的CSS,并附带代码-moz另一个解决方案是使用黑客Browser Hack

Hope this helps :) 希望这可以帮助 :)

I've ran this with and without the "!important" CSS declaration and saw a minor improvement for Firefox (and I mean very minor); 我已经在有和没有“!important” CSS声明的情况下运行了此程序,并且看到了Firefox的微小改进(我的意思是非常小的); I did make sure I cleared my history before each run but there could be a few reasons for that. 我确实确保在每次跑步之前都清除了自己的历史记录,但是可能有一些原因。 They use different engines so they're going to decide how they should load things differently and when ( http://www.quora.com/What-makes-one-web-browser-faster-than-another - an old article but gets the point across). 他们使用不同的引擎,因此他们将决定如何以不同的方式加载内容以及何时加载( http://www.quora.com/What-makes-one-web-browser-faster-than-another-一篇旧文章,但指出问题)。

The link Arjun for Browser Hacks is a good one to help optimize your CSS specific to the browser. 链接Arjun for Browser Hacks是一个很好的链接,可以帮助优化特定于浏览器的CSS。

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

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