Displaying a table with two cells positioned next to each other:
<table>
<td disabled>Content for the first cell</td>
<td style="margin-left:100px;" disabled>Content for the second cell</td>
</table>
Despite using margin-left:100px
, there is no space created between the first and second cells. How can I introduce spacing to the left of the second cell?
Adding Padding to the Left
padding-left:100px
The outcome will be:
By adding padding to the left of the second cell, it now has additional space of 100px. However, this only affects the content within the cell and not the background position.
Using Border-spacing Property
<table style="border-spacing: 100px 0; margin: 0 -100px">
This method results in:
If a third table cell is added, you will encounter:
To avoid spacing between every cell except the second one:
Dealing with Cellspacing
It's worth noting that the cellspacing
attribute creates spacing around all cells, which might not be desired. Additionally, some sources suggest that cellspacing
is not compatible with HTML5.