为什么不计算这个div高度?

时间:2012-11-26 11:04:33

标签: javascript jquery html5 css3

有人知道为什么没有正确计算黄箱的高度(100px)吗?

我需要知道定义css所以JavaScript-Part知道真正的高度......

<div id="footer">
 <div class="header">
  Header
 </div>
 <div class="content">
  Content blub    
 </div>
</div>​

这是一个jsFiddle - http://jsfiddle.net/3nM7f/

2 个答案:

答案 0 :(得分:2)

这是因为您使用百分比%而不是像素px来定义它。

您需要更改

.content{
    height:100%;   
    background-color:yellow;
}

.content{
    height:100px;   
    background-color:yellow;
}

并且所有部分都会正确显示。

jsfiddle此处。

答案 1 :(得分:1)

高度100%始终采用父div的高度。如果需要,您可以使用javascript设置其高度。您需要在网站标题中包含jquery js文件。语法可能不是100%正确,但您可以使用概念

var height = $(".footer").css("height") - $(".header").css("height");
$(".content").css("height",height);
相关问题