I am trying to have a flexbox element not become larger than the screen due to its content.
Here is some basic code:
section,
aside {
font-size: 1.5em;
}
#container1,
#container2 {
display: flex;
}
#overflower {
overflow-x: auto;
}
aside {
background-color: red;
flex-basis: 15em;
width: 15em;
min-width: 15em;
flex-grow: 0;
}
section {
background-color: green;
flex-grow: 1;
flex-basis: 15em;
}
<div id="container1">
<aside>Short text OK</aside>
<section>Short text OK</section>
</div>
<br>
<div id="container2">
<aside>Short text OK</aside>
<section>
<div id="overflower">
<table>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
<td>aaa</td>
</table>
</div>
</section>
</div>
I have done a jsfiddle to explain it as well: https://jsfiddle.net/51jxxe4p/2/
The left column has a fixed width and the right one should use the remaining space (proper behavior). But, if the table is too large, it will grow outside of the screen, which I try to prevent. I thought the #overflower
would prevent it, but it doesn't work. I tried to set width at 100% in various places, but without success either.