I'm using Bootstrap 4 to create responsive tables. On one page I have a 2-column layout like this:
|-----------------|---------------|
|Table |Image |
|-----------------|---------------|
The table is wrapped by <div class="table-responsive">. For the columns in the first row a specific column width is given as percentage:
<tr class="header">
<td style="width:20%;">Column 1</td>
<td style="width:10%;">Column 2</td>
<td style="width:30%;">Column 3</td>
<td style="width:30%;">Column 4</td>
<td style="width:10%;">Column 5</td>
</tr>
This layout works as expected: The table stretches to 100 % width of its parent div. But on small viewports content of some columns is overflowing. It gets even worse the more columns my table has. Check out this screenshot:
I could solve this by adding some CSS to make the content break to a new line if it is too long. But this is not what I want. Instead, I'd like the table columns to be of a fixed width and a horizontal scrollbar to be displayed if viewport width is too small for displaying the table as a whole. I tried to set table-layout:fixed but to no avail - content is still overflowing.
I was able to achieve the desired result by specifying table and column width in pixels. But then the table won't take the full width of its parent div on large viewports.
How can I get the desired effect (as I was able to by specifying widths in pixels) but make the table to always fill up 100 % of its parent div? I checked several questions on StackOverflow but none of them got me the desired output.
Thanks in advance.
