【问题标题】:How to make css max width in IE6 and 7?如何在 IE6 和 7 中设置 css 最大宽度?
【发布时间】:2014-01-14 14:32:30
【问题描述】:

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

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

很遗憾,它不适用于 IE 6 和 7。 我该如何解决?

提前致谢。

【问题讨论】:

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


    【解决方案1】:
    1. 在IE7中支持max-height属性:http://www.w3schools.com/cssref/pr_dim_max-height.asp,你可以通过this link使用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 */  
      }  
      

    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;
    }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2011-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-20
        • 1970-01-01
        • 1970-01-01
        • 2012-01-19
        • 2011-02-05
        相关资源
        最近更新 更多