93

I am trying to add a table with space between cell as the background colour of the cell is white and the background color of the table is blue, you can easily see that padding and margin are not working (I am applying it to the td), it will only add space inside of the cell.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Amra
  • 24,780
  • 27
  • 82
  • 92
  • 2
    possible duplicate of [How to set cellpadding and cellspacing in CSS?](http://stackoverflow.com/questions/339923/how-to-set-cellpadding-and-cellspacing-in-css) – user Mar 07 '14 at 20:46

7 Answers7

125

You want border-spacing:

<table style="border-spacing: 10px;">

Or in a CSS block somewhere:

table {
  border-spacing: 10px;
}

See quirksmode on border-spacing. Be aware that border-spacing does not work on IE7 and below.

Dominic Rodger
  • 97,747
  • 36
  • 197
  • 212
  • 2
    in IE7 and below, you can use the cellspacing attribute in the table tag. You can supply both to get it working in IE also. Other browsers will prioritize the style. – Tor Valamo Jan 15 '10 at 10:34
43
table { 
  border-spacing: 10px; 
} 

This worked for me once I removed

border-collapse: separate;

from my table tag.

simon
  • 12,666
  • 26
  • 78
  • 113
Kelly
  • 439
  • 4
  • 2
34

Mine is:

border-spacing: 10px;
border-collapse: separate;
JanBorup
  • 5,337
  • 1
  • 29
  • 17
  • 1
    i need to add the boder-collapse css property for the margin to take affect. thanks – ufk Jan 14 '16 at 14:51
4

Consider using cellspacing and cellpadding attributes for table tag or border-spacing css property.

Kniganapolke
  • 5,073
  • 5
  • 22
  • 19
4

cellspacing (distance between cells) parameter of the TABLE tag is precisely what you want. The disadvantage is it's one value, used both for x and y, you can't choose different spacing or padding vertically/horizontally. There is a CSS property too, but it's not widely supported.

SF.
  • 13,549
  • 14
  • 71
  • 107
3

Suppose cellspcing / cellpadding / border-spacing property did not worked, you can use the code as follow.

<div class="form-group">
  <table width="100%" cellspacing="2px" style="border-spacing: 10px;">
    <tr>                        
      <td width="47%">
        <input type="submit" class="form-control btn btn-info" id="submit" name="Submit" />
      </td>
      <td width="5%"></td>
      <td width="47%">
        <input type="reset" class="form-control btn btn-info" id="reset" name="Reset" />
      </td>
    </tr>
  </table>
</div>

I've tried and got succeed while seperate the button by using table-width and make an empty td as 2 or 1% it doesn't return more different.

Lewis86
  • 511
  • 6
  • 15
Ram
  • 115
  • 8
0

If you want separate values for sides and top-bottom.

<table style="border-spacing: 5px 10px;">
obliviJohn
  • 11
  • 3