[英]Why is this div height not calculated?
Does anybody know why the Height of the yellow-box is not calculated correctly (100px)? 有谁知道为什么黄色框的高度计算不正确(100像素)?
I need to know define the css so the JavaScript-Part knows the real height... 我需要知道定义CSS以便JavaScript-Part知道实际高度...
<div id="footer">
<div class="header">
Header
</div>
<div class="content">
Content blub
</div>
</div>
Here is a jsFiddle - http://jsfiddle.net/3nM7f/ 这是一个jsFiddle- http://jsfiddle.net/3nM7f/
It's because you're defining it using percentages %
instead of pixels px
. 这是因为您要使用百分比
%
而不是像素px
。
You need to change 你需要改变
.content{
height:100%;
background-color:yellow;
}
to 至
.content{
height:100px;
background-color:yellow;
}
and all your sections will appear correctly. 并且所有部分都将正确显示。
Height 100% always takes the height of the parent div. 高度100%始终采用父div的高度。 You can use javascript to set its height if you want.
您可以根据需要使用javascript设置其高度。 You need to include jquery js file in your website header.
您需要在网站标题中包含jquery js文件。 syntax maynot be 100% correct but you can use the concept
语法可能不是100%正确,但是您可以使用该概念
var height = $(".footer").css("height") - $(".header").css("height");
$(".content").css("height",height);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.