I want to have a table with padding between each of the cells, but not around the outer edge cells, that is, not around the table itself.
Using:
border-collapse : separate;
border-spacing : 0.5em;
gives me padding everywhere, while using:
border-collapse : collapse;
gives no padding anywhere.
Attempting an alternate approach, I can get padding solely between the cells horizontally using a td + td
selector. However I can't use a tr + tr
selector because it seems tr
ignores margin, padding and border rules.
And, of course, padding on a plain td
selector applies to all cells, even the outer-edges of the outer cells.
This only has to work for current-generation browser - no IE 6 or 7 for me thank you very much. And I am not going to loose any sleep over IE 8, though it would be nice if that worked.
The space between the table cells is controlled by the CELLSPACING attribute in the TABLE tag. By setting CELLSPACING to zero, you can remove all the space between the cells of your table.
Cell padding is the space between cell borders and the content within a cell. To set cell padding in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property padding.
This is a Default behavior of the table cells that there is some space between their Borders. To remove this space we can use the CSS border-collapsing Property. This Property is used to set the borders of the cell present inside the table and tells whether these cells will share a common border or not.
Under Settings, click Properties. Click the Table tab, and then click Options. Under Default cell spacing, select the Allow spacing between cells check box, and then enter the measurement that you want.
This isn't a perfect solution, as it uses padding instead of border spacing. Possibly it will work for your problem though.
HTML:
<table>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</table>
And the CSS:
table {
border: 1px red solid;
border-collapse: separate;
}
td {
background-color: green;
border: 1px black solid;
padding: 10px;
}
td:first-child {
padding-left: 0px;
}
td:last-child {
padding-right: 0px;
}
tr:first-child td {
padding-top: 0px;
}
tr:last-child td {
padding-bottom: 0px;
}
Produces:
Also on jsFiddle.
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