如何在IE6和7中制作css最大宽度?

Dan*_*Fox 4 css internet-explorer-7 internet-explorer-6

我在我的网站上使用这个css代码:

img {
  max-height: 800px;
  max-width: 600px;
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,它不能与IE 6和7一起使用.我该如何解决?

提前致谢.

Sng*_*ger 10

  1. IE7支持max-height属性:http: //www.w3schools.com/cssref/pr_dim_max-height.asp,您可以使用IE7通过此链接对其进行测试.
  2. 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 */  
    }  
    
    Run Code Online (Sandbox Code Playgroud)

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"});  
    });
}
Run Code Online (Sandbox Code Playgroud)

2012.11.27更新:

img{
    min-height:800px;height:auto !important;height:800px;
    min-width:600px;width:auto !important;width:600px;
}
Run Code Online (Sandbox Code Playgroud)