How do I make a table element to horizontally overflow it's parent container? I would like to avoid setting table width, since it should be sum of the columns.
I'm trying to set columns widths, but as soon as they reach parents width, they does not grow anymore.
Following snippet demonstrates two tables with different column widths, but they are both rendered equally. The second table should actually overflow the parent.
.container {
width: 300px;
background: #ccc;
overflow: auto;
}
table {
table-layout: fixed;
border-collapse: collapse;
margin-bottom: 10px
}
td,
th {
border: solid 1px red;
text-align: center
}
#table1 col {
width: 100px
}
#table2 col {
width: 200px
}
<div class="container">
<table id="table1">
<colgroup>
<col /><col /><col />
</colgroup>
<thead>
<tr>
<th>A</th><th>B</th><th>C</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td><td>2</td><td>3</td>
</tr>
</tbody>
</table>
<table id="table2">
<colgroup>
<col /><col /><col />
</colgroup>
<thead>
<tr>
<th>A</th><th>B</th><th>C</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td><td>2</td><td>3</td>
</tr>
</tbody>
</table>
</div>