I have a table with a colored background and I need to specify the padding between the table and it\'s content, I.E. cells.
The table tag doesn\'t seem to accept a paddi
You could set a margin for the table. Alternatively, wrap the table in a div and use the div's padding.
Funny, I was doing precisely this yesterday. You just need this in your css file
.ablock table td {
padding:5px;
}
then wrap the table in a suitable div
<div class="ablock ">
<table>
<tr>
<td>
You can try the border-spacing property. That should do what you want. But you may want to see this answer.
Here's the thing you should understand about tables... They're not a tree of nested independent elements. They're a single compound element. While the individual TDs behave more or less like CSS block elements, the intermediate stuff (anything between the TABLE and TD, including TRs and TBODYs) is indivisible and doesn't fall into either inline nor block. No random HTML elements are allowed in that other-dimensional space, and the size of such other-dimensional space isn't configurable at all through CSS. Only the HTML cellspacing
property can even get at it, and that property has no analog in CSS.
So, to solve your problem, I'd suggest either a DIV wrapper as another poster suggests, or if you absolutely must keep it contained in the table, you have this ugly junk:
<style>
.padded tr.first td { padding-top:10px; }
.padded tr.last td { padding-bottom:10px; }
.padded td.first { padding-left:10px; }
.padded td.last { padding-right:10px; }
</style>
<table class='padded'>
<tr class='first'>
<td class='first'>a</td><td>b</td><td class='last'>c</td>
</tr>
<tr>
<td class='first'>d</td><td>e</td><td class='last'>f</td>
</tr>
<tr class='last'>
<td class='first'>g</td><td>h</td><td class='last'>i</td>
</tr>
</table>
With css, a table can have padding independently of its cells.
The padding property is not inherited by its children.
So, defining:
table {
padding: 5px;
}
Should work. You could also specifically tell the browser how to pad (or in this case, not pad) your cells.
td {
padding: 0px;
}
EDIT: Not supported by IE8. Sorry.
table {
border: 1px solid transparent;
}