ie6不支持css maxheigth 最大高度解决办法集

主要是css hack方法,利用ie6支持或者不支持的符号来完成任务。

你可能会想到我前面说过的expression,在css里面计算该容器的高度。

是的,这样能够达到我们的要求。代码部分如下

 代码如下 复制代码
overflow:auto;/*超出部分显示滚动条*/
_height: expression(
this.scrollHeight < 100 ? "100px" :
(this.scrollHeight > 200 ? "200px" : "auto");
 


我上面说的只是ie6实现它。废话不多说,看代码

 代码如下 复制代码
<style type="text/css">
.contain{height:200px;overflow:auto;background:#eee;}
.post{_height:100px;min-height:100px;background:#ccc;}
</style>
<div class="contain">
<div class="post">
今天正好遇到了min-height的问题,干脆在这里记录下来。我是喜欢联想的人,所以在这里又倒腾出了ie6支持max-height,以及ie6同时支持min-height与max-height的方法
</div>
</div>
 


我打算使用css自带的max- height标签,但是火狐支持最大高度的写法,而ie6、Chrome不支持该写法,害得我马上到网上恶补css bug写法。最后找到一行代码,只是代码写的是最大宽度的写法:

 代码如下 复制代码
.a{expression(this.clientWidth > 950?"950px": "auto" ); }
 

在我修改为高度后,又出现了问题。弄了半天,原来是我的this.后的代码写错。晕了,正确的最大高度代码写法:

 代码如下 复制代码
.a{ overflow: auto; max-height:84px; height: expression_r( this.scrollHeight > 83 ? "84px" : "auto" );}
 

这样写的话,在ie6、ie7、ff下可以得到想要的效果,而在Chrome谷歌浏览器下不支持该写法。因此我又去网上找了一下Chrome的bug。发现Chrome的bug一般可以用-webkit-来解决。因此修改之后的写法为:

 代码如下 复制代码
.a ul{ overflow: auto; max-height:84px; -webkit-max-height:84px; height: expression_r( this.scrollHeight > 83? "84px" : "auto" );}
 

我的html代码如 下:switch090405_cont2为div的外观设置

 代码如下 复制代码
<div class="switch090405_cont2 a">
      <ul>
           <li>http://www.hzhuti.com/HTC/G11/</li>
           <li>列表内容</li>
           <li>列表内容</li>
           <li>列表内容</li>
      </ul>
</div>
 

----------------------------------------------------------

 代码如下 复制代码
#test { min-height:100px; background:#BBB; _height:100px; overflow: visible; }

#page{

background:#F00;

min-height:500px;
height:auto !important;
height:500px;

overflow:visible;

}
 

就是这句overflow:visible使IE们能够当作height:auto来处理

jquery的实现方法

上面的代码还没有加入IE6的判断,完整代码如下:

 代码如下 复制代码
if($.browser.msie&amp;&amp;
($.browser.version === "6.0")){
$(".entry").each(function(){
if($(this)[0].scrollHeight>500)
$(this).css({"height":"500px","overflow":"hidden"});
});}
 

当然你也可以通过css表达式来实现IE6支持max-height属性

 代码如下 复制代码
.entry{

height: expression( this.scrollHeight > 500 ? "500px" : "auto" );

 /* sets max-height for IE */
}
 

下面简单的介绍一下min-height实现方法
方法一:

 代码如下 复制代码
<style type="text/css">
.show{background:#ccc;min-height:100px;_height:100px;}
</style>
<div class="show">牛魔王的世界观测试御用文字!</div>
 

方法二:

 代码如下 复制代码
<style type="text/css">
.show{background:#ccc;height:auto!important;height:100px;min-height:100px; }
</style>
<div>牛魔王的世界观测试御用文字!</div>
 

最后也是一个常用的办法就是


1、IE6不识别max-height:500px和height:auto !important这两句,超过500px(也就是我们所希望的最大高度)后的内容将自动以藏;

不过我产推荐这种办法哦,会影响网站的美观的。

更多详细内容请查看:http://www.111cn.net/cssdiv/css/42109.htm

原文地址:https://www.cnblogs.com/phpfans2012/p/2379513.html