增加最大/最小高度:div?

时间:2011-12-29 23:59:29

标签: javascript css css3 height

所以我有一个内容div,它最适合400px的增量高度。

如果内容大小不同,那么底部看起来很有趣,即如果由于里面的内容它的高度为638像素高。但是,如果它是800px,它看起来很棒(1200和1600等相同)

是否可以使用#div { min-height: 800px; },但如果内容甚至有801px,请使用CSS或Javascript将其与#div { min-height: 1200px; }对齐?

1 个答案:

答案 0 :(得分:2)

这样的东西?

// set the height of a div with an id of 'test'
$(document).ready(function() {
 var height = $('#test').height();
 if(height % 400) {
     height = height - (height % 400) + 400;
 }
 $('#test').css('height',height+'px');
});
相关问题