Ali Sheikhpour Ali Sheikhpour - 2 months ago 5
CSS Question

Can not reset TD style

I have removed padding from all TD elements in stylesheet. But I have a special table having

cellpadding="10"
. Its TD are rendered having 0px padding due to above mentioned style.

how should I reset TD padding to nothing so it inherits the 10px padding from cellpadding?



td {padding:0}

#specialtable td {
/* What should I write here? */
}

<table id="specialTable" cellpadding="10" style="border:1px solid #555555">
<tr>
<td>test</td>
</tr>
</table>




Answer

You can use the :not pseudo-class to define the padding for all td except those under a #specialTable.

table:not(#specialTable) td {
  padding: 0;
}
<table id="specialTable" cellpadding="10" style="border:1px solid #555555">
  <tr>
    <td>test</td>
  </tr>
</table>

Comments