【发布时间】:2014-01-14 14:32:30
【问题描述】:
我在我的网站中使用这个 css 代码:
img {
max-height: 800px;
max-width: 600px;
}
很遗憾,它不适用于 IE 6 和 7。 我该如何解决?
提前致谢。
【问题讨论】:
标签: css internet-explorer-7 internet-explorer-6
我在我的网站中使用这个 css 代码:
img {
max-height: 800px;
max-width: 600px;
}
很遗憾,它不适用于 IE 6 和 7。 我该如何解决?
提前致谢。
【问题讨论】:
标签: css internet-explorer-7 internet-explorer-6
IE6 及更早版本不支持 max-height 属性。但是你可以使用 CSS 来破解它:
img {
max-height: 800px;
_height:expression(this.scrollHeight > 800 ? "800px" : "auto"); /* sets max-height for IE6 */
max-width: 600px;
_width:expression(this.scrollWidth > 600 ? "600px" : "auto"); /* sets max-width for IE6 */
}
2.1 用jQuery解决:
if($.browser.msie&&($.browser.version == "6.0")&&!$.support.style){
$("img").each(function(){
if($(this)[0].scrollHeight>800)
$(this).css({"height":"800px","overflow":"hidden"});
});
}
2012.11.27 更新:
img{
min-height:800px;height:auto !important;height:800px;
min-width:600px;width:auto !important;width:600px;
}
【讨论】:
您可以获得在旧版 IE 中工作的最小和最大宽度/高度:http://javascript.about.com/library/blwidth.htm
【讨论】: