如果你有一個是這樣的HTML文檔:有沒有CSS高度:休息屬性?
<body>
<div id="top"></div>
<div id="rest"></div>
</body>
,我給「頂」的div 40像素的高度,是有辦法讓「休息」 div的高度的其餘部分身體在CSS。我知道這是可能在Javascript中這樣
function derest(){
var bodyheight = window.getComputedStyle(document.getElementsByTagName('body')[0], null).height;
bodyheight = bodyheight.substring(0, bodyheight.length - 2);
var topheight = window.getComputedStyle(document.getElementById('top'), null).height;
topheight = topheight.substring(0, topheight.length - 2);
restheight = bodyheight - topheight;
document.getElementById("rest").style.height = restheight;
}
但是這需要花費大量的時間,所以有沒有更好的方式來做到這一點?
這是可能的Flexbox的。 (更具體地說'flex-grow:1')。有一個很好的谷歌搜索。 –