【发布时间】:2011-12-30 12:40:08
【问题描述】:
基本上
我很少有 div 具有灵活的高度和固定的填充,因此很难让它们都具有相同的高度,
我正在尝试这样:
$(document).ready(function(){
$('.LevelCnt_2,.LevelCnt_2 .content,.LevelCnt_1,.LevelCnt_1 .content').outerHeight( $('header:eq(0)').outerHeight() );
console.log($('header:eq(0)').outerHeight(true));
});
但问题是标题并不总是最高的,所以我需要
检查哪一个更高(考虑到有多个 .content 元素)
应用外层高度 给他们所有人
但我找不到一个好的/漂亮的方法(有一个解决方案,但我需要很多 if 和变量)来做到这一点
有什么线索吗?
-编辑-
在等待的时候我想出了这个
$(document).ready(function(){
var height = 0;
$('.LevelCnt_2,.LevelCnt_2 .content,.LevelCnt_1,.LevelCnt_1 .content,header').each(function(){
if($(this).outerHeight() > height){
height = $(this).outerHeight();
}
});
$('.LevelCnt_2,.LevelCnt_2 .content,.LevelCnt_1,.LevelCnt_1 .content,header').each(function(){
$(this).outerHeight(height);
});
console.log('highest height is '+height); //it doesn't output the highest value
});
但大多数 div 都在 display:none 中,这是问题所在吗?
【问题讨论】:
-
我想知道这段代码“('header:eq(0)')”。据我所知,您为 HTML 标记“
”添加了高度,不是吗?
标签: javascript jquery height