对于大多数人来说,这可能非常容易。但是我需要一个小片段,它查找div的当前高度(div的高度基于其中的内容而动态变化),然后将该值设置为css类的min-height值。
基本上这意味着我希望这个容器的最小高度与其当前高度完全相同。这可能是一个快速解决的问题 :)
对于大多数人来说,这可能非常容易。但是我需要一个小片段,它查找div的当前高度(div的高度基于其中的内容而动态变化),然后将该值设置为css类的min-height值。
基本上这意味着我希望这个容器的最小高度与其当前高度完全相同。这可能是一个快速解决的问题 :)
如果我理解你的意思正确,你可以按照以下步骤操作:
$(".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("<%= this.your_element_id.ClientID %>");
elt.style.minHeight = elt.clientHeight + 'px';