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

时间:2012-02-25 08:24:59

标签: css internet-explorer-7 internet-explorer-6

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

img {
  max-height: 800px;
  max-width: 600px;
}

不幸的是,它不适用于IE 6和7。 我该如何解决?

提前致谢。

2 个答案:

答案 0 :(得分:10)

  1. IE7支持max-height属性:http://www.w3schools.com/cssref/pr_dim_max-height.asp,您可以使用IE7 this link对其进行测试。
  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 */  
    }  
    
  3. 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;
    }
    

答案 1 :(得分:1)

你可以获得最小和最大宽度/高度在旧的IE中工作:http://javascript.about.com/library/blwidth.htm