`
paulfzm
  • 浏览: 874181 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

让ie6 实现 max-height 的几种方法

 
阅读更多

解决IE6不支持max-height(jquery或css)

常用2种方法,一种是css方法,一种设计js方法:

1、利用css表达式来实现IE6支持max-height属性

.entry{height: expression( this.scrollHeight > 500 ? “500px” : “auto” ); /* sets max-height for IE */}

2、利用jquery实现IE6支持max-height属性

$(“.entry”).each(function(){
if($(this)[0].scrollHeight>500)
$(this).css({“height”:”500px”});
});

原理: 在IE6中可以通过设定height来达到max-height的效果. 循环所有要加max-height属性的DOM元素,判断他的scrollHeight大于你要设置的最大高度 如果超过了就通过设置height为最大高度

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

if($.browser.msie&&($.browser.version == “6.0″)&&!$.support.style){
$(“.entry”).each(function(){
if($(this)[0].scrollHeight>500)
$(this).css({“height”:”500px”,”overflow”:”hidden”});
});}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics