I am trying to hide columns in a table using <col>
and visibility:collapse
as described here:
Is it possible to hide / show table columns by changing the CSS class on the col element only?
Now I found out that this solution seems to work only with "normal" tables but not when having border-collapse:collapse
. In that case, only the content of the column is hidden and the content of the subsequent columns is shifted to the left.
See here: http://jsfiddle.net/seeLcc2p/3/
body {
padding: 5px;
}
table {
border: 1px solid black;
border-collapse: collapse;
/* border-collapse:separate; */
}
.hide {
visibility: collapse;
}
<head>
<style>
/* css code */
</style>
</head>
<body>
<table border="1">
<col width="100" />
<col width="50" class="hide" />
<col width="100" />
<col width="100" />
<tr>
<td>Row 1 Col 1</td>
<td>Row 1 Col 2</td>
<td>Row 1 Col 3</td>
<td>Row 1 Col 4</td>
</tr>
<tr>
<td>Row 2 Col 1</td>
<td>Row 2 Col 2</td>
<td>Row 2 Col 3</td>
<td>Row 2 Col 4</td>
</tr>
<tr>
<td>Row 3 Col 1</td>
<td>Row 3 Col 2</td>
<td>Row 3 Col 3</td>
<td>Row 3 Col 4</td>
</tr>
</table>
</body>
When having border-collapse:separate;
everything is as excepted, with border-collapse:collapse;
the layout is broken…
Any ideas how to fix this or what I'm doing wrong?
Tried in Firefox 57.0.4.