如果你有一个是这样的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')。有一个很好的谷歌搜索。 –