I have two questions:
Thanks!
table {
border-collapse: collapse;
padding:30px; /* Padding not working */
}
<table>
<tr>
<td>cell</td>
<td>cell</td>
</tr>
<tr>
<td>cell</td>
<td>cell</td>
</tr>
</table>
is there a logical explanation, Why is this working like that?
When you collapse the borders, it joins adjacent borders together.
The border around the outside edge of the table is adjacent to the outside borders of the outside cells.
If those borders are joined together then you can't put padding between them. There is no "between".
Is there a CSS workaround for that situation?
Not, in general, a plain one.
You need to add another element around the table, and place the padding there.
In this case, you already have the container div, so you can move the padding to that.
.container {
width: 400px;
height: 300px;
margin: 40px auto;
background: #ddd;
padding: 30px;
}
table {
text-align: center;
width: 100%;
height: 100%;
border-collapse: collapse;
}
td {
border: 1px solid red;
}
<div class="container">
<table>
<tr>
<td>cell</td>
<td>cell</td>
</tr>
<tr>
<td>cell</td>
<td>cell</td>
</tr>
</table>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With