【发布时间】:2015-10-07 23:53:04
【问题描述】:
这对你们大多数人来说可能真的很容易。但我需要一个小的 sn-p 来查找 div 的当前高度(div 具有基于其中内容的动态高度) 然后将该值设置为 css 类的 min-height 值。
基本上,这意味着我希望这个容器的最小高度与当前高度完全相同。这可能是一个快速的:)
【问题讨论】:
标签: javascript jquery css
这对你们大多数人来说可能真的很容易。但我需要一个小的 sn-p 来查找 div 的当前高度(div 具有基于其中内容的动态高度) 然后将该值设置为 css 类的 min-height 值。
基本上,这意味着我希望这个容器的最小高度与当前高度完全相同。这可能是一个快速的:)
【问题讨论】:
标签: javascript jquery css
如果我理解正确,您可以执行以下操作:
$(".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';
【讨论】: