CSS:强制子级使用父级(表格单元格)高度

Bri*_*ham 5 html css height sticky-footer css-tables

#wrapper {
    display: table;
    min-height: 100%;
    height: 100%;
    margin: 0px auto;
}

#header-wrap,
#content-wrap,
#footer-wrap {
    display: table-row;
    height: 1px;
}
#content-wrap {
    height: auto;
}

<div id="wrapper">
    <div id="header-wrap"></div>
    <div id="content-wrap">
        <section id="content"></section>
    </div>
    <div id="header-wrap"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

#wrapper充当表格#header-wrap,其中 、#content-wrap#footer-wrap是帮助将页脚推到页面底部的表格单元格。

如何让部分 #content 填充 #content-wrap高度?

我不会使用绝对定位。

Joh*_*uff 0

由于#content-wrap浏览器确定了高度,因此您所要做的就是设置#content为父元素高度的 100%。

#content{
    height:100%;
}
Run Code Online (Sandbox Code Playgroud)

如果它没有设置为那个高度,我猜想可能稍后设置了一些 css 属性来覆盖这个高度。