[英]How to make div inside table fill up remaining space
Given the HTML structure below, how do I make td.expand
fill up the remaining vertical space of #outer
?鉴于下面的 HTML 结构,我如何让td.expand
填充#outer
的剩余垂直空间? I've tried various solutions (including Flexbox), but nothing worked for me.我尝试过各种解决方案(包括 Flexbox),但对我没有任何帮助。 Unfortunately, I'm stuck with the two tables, so assume the HTML structure cannot be changed.不幸的是,我坚持使用这两个表,所以假设 HTML 结构无法更改。 Also, assume that #outer
is inside a modal that can be resized, so its height is dynamic (ie, as the user resizes the modal, the height of #outer
is changed, and td.expand
should continuously fill up the vertical space such that the header and footer will always be at the top and bottom of #outer
, respectively.此外,假设#outer
在一个可以调整大小的模态内,因此它的高度是动态的(即,当用户调整模态大小时,# td.expand
#outer
连续填充垂直空间,例如header 和页脚将始终分别位于#outer
的顶部和底部。
#outer { height: 400px; /* dynamic */ background: skyblue; }.fixed { height: 20px; } header, footer { height: 50px; border: 1px solid black; }
<div id="outer"> <div id="container"> <header>Header</header> <table class="outer-table"> <tr> <td> <div class="content"> <table class="inner-table"> <tr><td class="expand">This should fill up remaining vertical space.</td></tr> </table> </div> </td> </tr> <tr class="fixed"><td>Fixed height</td></tr> <tr class="fixed"><td>Fixed height</td></tr> </table> <footer>Footer (should be pushed to the bottom)</footer> </div> </div>
The output should look like this, where td.expand
fills up the remaining space of #outer
: output 应如下所示,其中td.expand
填充了#outer
的剩余空间:
Just calculate the the height
by subtracting occupied height
by footer
and header
and two tr
from the parent height
只需从父height
中减去footer
占用的height
和header
和两个tr
即可计算出height
#outer { height: 400px; background: skyblue; } header, footer { height: 50px; border: 1px solid black; }.content { background: red; height: 245px; }
<div id="outer"> <div id="container"> <header>Header</header> <table class="outer-table"> <tr> <td> <div class="content"> <table class="inner-table"> <tr> <td class="expand">This should fill up remaining height of #outer (blue)</td> </tr> </table> </div> </td> </tr> <tr> <td>Fixed height</td> </tr> <tr> <td>Fixed height</td> </tr> </table> <footer>Footer</footer> </div> </div>
I played a little with flex.我玩了一点flex。 Did you need such a result?你需要这样的结果吗? The red block is stretchable.红色块是可拉伸的。
#container { display: flex; justify-content: space-between; flex-direction: column; height: 100%; width: 100%; }.outer-table { display: flex; height: 100%; }.outer-table > tbody { display: flex; flex-direction: column; width: 100%; }.outer-table > tbody > tr:first-of-type { flex: 1 1 auto; }.outer-table > tbody > tr > td { display: flex; flex-direction: column; height: 100%; } #outer { height: 400px; background: skyblue; } header, footer { height: 50px; border: 1px solid black; }.content { background: red; flex: auto; }
<div id="outer"> <div id="container"> <header>Header</header> <table class="outer-table"> <tr> <td> <div class="content"> <table class="inner-table"> <tr><td class="expand">This should fill up remaining height of #outer (blue)</td></tr> </table> </div> </td> </tr> <tr><td>Fixed height</td></tr> <tr><td>Fixed height</td></tr> </table> <footer>Footer</footer> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.