下面的HTML很簡單,可以做我想做的事情。綠色的身體向下伸展以填滿窗戶。CSS高度100%使元素高度超過100%
<body style="margin:0">
<div style="height:100%;display:flex;flex-direction:column">
<div style="background:#d0d0ff">
This is a header
</div>
<div style="background:#d0ffd0;flex-grow:1">
This is the body.
</div>
</div>
</body>
但是,如果我替換正文一些柔性列,我給他們height:100%
,因爲我希望他們可拉伸至底部,newdiv
居然得到了高度的它大於100%的容器中,使一切滾動。爲什麼100%不是100%在這裏?
<body style="margin:0">
<div style="height:100%;display:flex;flex-direction:column">
<div style="background:#d0d0ff">
This is a header
</div>
<div style="background:#d0ffd0;flex-grow:1">
<!-- The new part -->
<div id='newdiv' style="display:flex;flex-direction:row; height:100%">
<div style="background:#ffd0d0"> Col 1 </div>
<div> Col 2 </div>
</div>
</div>
</div>
</body>
你能提供一個小提琴,感謝您的 –
產生的代碼比你的截圖不同的輸出對我來說:https://jsfiddle.net/ok20071g/1/ –
Ug ...很抱歉...我忘記了<!doctype html>,並且處於怪癖模式。 Nevermind ... –