This is more of a "tell me why it doesn't work" instead of "help me fix it" question. If I try to apply padding to a thead or tr element within a table, it doesn't work. The only way padding works is if I apply it directly to the th or td element. Why is this so? Is there an easy way to apply padding to the entire thead or tr or is adding it to the th and td the only option?
<table>
<thead>
<tr>
<th>Destination</th>
<th>Size</th>
<th>Home Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>test 1</td>
<td>test 2</td>
<td>test 3</td>
</tr>
</tbody>
</table>
Notice the 10px of padding on the thead.
table {
width: 100%;
}
thead {
text-align: left;
background-color: yellow;
padding: 10px;
}
http://jsfiddle.net/5VQB7/
In Tables, we can add padding to individual cells as well as specify space between different cells.
Complete HTML/CSS Course 2022 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.
You can easily set padding inside the table cells using the CSS padding property. It is a valid way to produce the same effect as the table's cellpadding attribute. Similarly, you can use the CSS border-spacing property to apply the spacing between adjacent table cell borders like the cellspacing attribute.
The cell padding attribute places spacing around data within each cell. The cell spacing attribute places space around each cell in the table.
http://www.w3.org/TR/CSS2/box.html#propdef-padding
'padding'
Applies to: all elements except table-row-group, table-header-group, table-footer-group, table-row, table-column-group and table-column
Try placing the padding in the th
element instead. Typically you want to add padding to the th
or td
element, depending on the circumstance.
thead th {
padding: 10px;
}
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