I need a table which spans the full width of the parent container. The table's header cell cannot have any border while the data cell should. The cell borders should be uniformly 1px wide on all 4 sides, which means that the border needs to collapse. When I have styled my table like this in CSS I notce that the total table width is 100% + 1px. Could anyone help me and tell me what am I doing wrong?
* {
box-sizing: border-box;
}
div {
width: 200px;
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
td,
th {
border: 1px solid #d3e0ee;
padding: 5px;
}
th {
border: 0px solid white;
padding: 6px;
}
<div>
<table>
<tr>
<th>Col 1</th>
<th>Col2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
</div>
Demo also at https://jsfiddle.net/fbwyx66o/4/ (try in Chrome)
Edit 1:
When the border is set to transparent (i.e. border: 1px solid transparent;
) the overflow issue is gone but the browser still renders only half of the right hand side border. Please compare the th and td right border on the screenshot below: