r/csshelp • u/Sparky2199 • Mar 05 '21
How can I prevent a child from expanding its parent?
I have two divs aligned horizontally in a parent div. The first div's height depends on its contents, and the second div contains a long table. I want to make the table scrollable, and constrain its max height to the first div's height.
Here's a simplified version of what I have so far:
<div class="row">
<div class="col-lg-6 col-xxl-3">
<div class="card card-custom card-stretch gutter-b">
<form class="form">
<!-- Dynamic height based on form elements -->
</form>
</div>
</div>
<div class="col-lg-6 col-xxl-9">
<div style="overflow: auto !important;height: inherit;">
<table class="table">
<!-- Scrollable, should NOT be higher than the form -->
</table>
</div>
</div>
</div>What I get:
┌────────────────────────────────┐
│┌──────┐┌──────────────────────┐│
││ Form ││ ││
│└──────┘│ table ││
│ │ with ││
│ │ many rows ││
│ │ ││
│ └──────────────────────┘│
└────────────────────────────────┘What I want:
┌────────────────────────────────┐
│┌──────┐┌──────────────────────┐│
││ Form ││ scrollable table ┃││
│└──────┘└──────────────────────┘│
└────────────────────────────────┘The problem is that the table is much taller than the form, and I don't know how to make it exactly as tall, and scrollable without javascript. As you can see, I've tried using height: inherit;, but it didn't work.
I'm using bootstrap and the Metronic admin template.