让jquery使用min-height而不仅仅是height

时间:2011-08-05 00:44:27

标签: javascript jquery

代码:

function setEqualHeight(columns) {
    var tallestcolumn = 0;
    columns.each(function(){
        currentHeight = $(this).height();
        if(currentHeight > tallestcolumn){
            tallestcolumn  = currentHeight;
        }
    });
    if (tallestcolumn <= 1000) {
        columns.height(tallestcolumn + 4);
    }
}
$(document).ready(function() {
    setEqualHeight($("#main-content-bottom-bg  > div"));
});

我知道它可能很简单,但我无法弄清楚我给的是什么。我会想到这样的事情:

columns.minheight(tallestcolumn + 4);

感谢。

3 个答案:

答案 0 :(得分:1)

差不多......试试:

columns.css('min-height', (tallestcolumn + 4) + 'px');

类似于:jQuery - Set min-height of div

答案 1 :(得分:1)

使用此功能:

 function setEqualHeight(columns){
      var tallestcolumn = 0;
      columns.each(function(){
           currentHeight = $(this).height();
           if(currentHeight > tallestcolumn){
                tallestcolumn  = currentHeight;
           }
      });
      if (tallestcolumn <= 1000) {
           columns.css("min-height",(tallestcolumn + 4)+"px");
      }
 }
 $(document).ready(function() {
     setEqualHeight($("#main-content-bottom-bg  > div"));
 });

答案 2 :(得分:0)

请改为尝试:

columns.css('min-height',(tallestcolumn + 4)+'px');