我有div(#child
),它不會擴展到它的父級的全部高度(#parent
)。我已經爲html
和body
設置了高度。它可以工作,如果我將父母的身高設置爲100%,但我希望父母具有最小身高,並且孩子可以擴展到父母的身高。內部的div 100%的高度不能在div中使用min-height
HTML:
<html>
<body>
<div id="parent">
<div id="child">
<p>This area should be have the same height as it's parent.</p>
</div>
</div>
</body>
</html>
CSS:
html, body, header, h1, p { margin: 0; padding: 0; }
html { background-color: #DDD; height: 100%; }
body { background-color: #DAA; height: 100%; }
#parent {
min-height: 70%;
height: auto !important;
height: 70%;
background-color: #AAD;
}
#child {
height: 100%; /* why isn't this working ? */
width: 80%;
margin: auto;
background-color: #ADA;
}
的jsfiddle:http://jsfiddle.net/nxVNX/11/
我拿起這裏的最小高度片段:http://css-tricks.com/snippets/css/cross-browser-min-height/並假定它是最佳做法。甚至沒有試圖擺弄這一點。從現在開始,我會變得更加不可思議:)) –