jQuery – 设置div的最小高度

对大多数人来说这可能很容易。 但我需要一个小片段来查找div的当前高度(div具有基于其内部内容的动态高度),然后在css类的min-height值中设置该值。

基本上这意味着我希望这个容器的最小高度与它的当前高度完全相同。 这可能很快:)

只是一个概念certificate!

// attend for dom ready $(function() { // hide .foo before we get it's height $('.foo').hide(); // get the height, also the one mentioned below is a good one! var foo_height = $('.foo').height(); // see if the actual height respect our needs! esample 180px if ( foo_height > 180 ) { // set the height and show it! //$('.foo').css('height', foo_height + 'px').show(); OR try $('.foo').height( foo_height ).show(); } else { //do something else here } }); 

这应该按预期工作!

如果我理解正确,您可以执行以下操作:

 $(".foo").css("min-height", function(){ return $(this).height(); }); 
 var elt = document.getElementById("<%= this.your_element_id.ClientID %>"); elt.style.minHeight = elt.clientHeight + 'px';