Javascript jQuery-设置div的最小高度
这对你们大多数人来说可能真的很容易。但是我需要一个查找div当前高度的小片段(div有一个基于其内部内容的动态高度) 然后在css类的最小高度值中设置该值Javascript jQuery-设置div的最小高度,javascript,jquery,css,Javascript,Jquery,Css,这对你们大多数人来说可能真的很容易。但是我需要一个查找div当前高度的小片段(div有一个基于其内部内容的动态高度) 然后在css类的最小高度值中设置该值 基本上,这意味着我希望这个容器的最小高度与当前高度完全相同。这可能是一个简单的例子:)如果我理解正确,您可以执行以下操作: $(".foo").css("min-height", function(){ return $(this).height(); }); 只是一个概念的证明 // attend for dom re
基本上,这意味着我希望这个容器的最小高度与当前高度完全相同。这可能是一个简单的例子:)如果我理解正确,您可以执行以下操作:
$(".foo").css("min-height", function(){
return $(this).height();
});
只是一个概念的证明
// 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
}
});
这应该是预期的工作 var elt=document.getElementById(“”);
var elt = document.getElementById("<%= this.your_element_id.ClientID %>");
elt.style.minHeight = elt.clientHeight + 'px';
elt.style.minHeight=elt.clientHeight+'px';
是的,这是有效的:)我之所以问这个问题,是因为我有一个未指定高度的div,它在被其他内容填充之前被清空了。根据容器中的内容使整个容器的大小动态变化。在“无内容”和“内容”之间的这个小间隙中,div在增长到所需大小之前会收缩到其最小高度。这里的缺点是div的大小不是动态地减小,而是向上。你知道解决这个问题的好办法吗?