I have a parent element which has a max-width
but inside I have a table that I want to expand past that max-width
, but only if it's necessary because of the content on the table.
Here's a fiddle so you can see: https://jsfiddle.net/z6nbc75g/
Try clicking the "add columns" button a few times to see how when you add too many, they start getting compressed instead of making the table wider.
Here's the code:
.parent {
width: 100%;
max-width: 20rem;
}
.table .row {
display: flex;
border: 1px solid blue;
padding: 4px;
}
.table .col {
border: 1px solid red;
padding: 2px;
}
<div class="parent">
<div class="table">
<div class="row">
<div class="col">lorem ipsum</div>
<div class="col">lorem ipsum</div>
</div>
<div class="row">
<div class="col">lorem ipsum</div>
<div class="col">lorem ipsum</div>
</div>
<div class="row">
<div class="col">lorem ipsum</div>
<div class="col">lorem ipsum</div>
</div>
<div class="row">
<div class="col">lorem ipsum</div>
<div class="col">lorem ipsum</div>
</div>
</div>
</div>