I am facing an issue with multiple children inside a parent container that has the CSS properties display: flex
and flex-direction: column
.
There is a toggle button on the webpage which removes one of the children when clicked.
The problem I need to solve is making sure that the table height expands to fill all the remaining space when any child is removed.
.parent {
border: black 1px solid;
height: 260px;
display: flex;
flex-direction: column;
}
.child {
padding: 5px;
}
#table {
display: table;
height: 160px;
}
.tr {
display: table-row;
padding: 5px;
}
.td {
display: table-cell;
padding: 5px;
width: 150px;
border: #000000 solid 1px;
margin: 5px;
}
<div class="parent">
<div class="child">
Child1
</div>
<div class="child">
Child2
</div>
<div class="child">
Child3
</div>
<div class="child">
<div id="table">
<div class="tr">
<div class="td">Row 1, <br />Column 1</div>
<div class="td">Row 1, Column 2</div>
<div class="td" style="background:#888888;"></div>
</div>
<div class="tr">
<div class="td">Row 2, <br />Column 1</div>
<div class="td" style="background:#888888;"></div>
<div class="td">Row 2, Column 2</div>
</div>
</div>
</div>
</div>
After removing Child2, the table shifts up but doesn't adjust its height, causing scrollbars to appear within the table content.