Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add space between two columns

I have an HTML table. I need to have spacing between the table columns, but not the table rows.

My table columns also have border around them:

<table>
<tr>
    <td style="padding:0 15px 0 15px;">hello</td>
    <td style="padding:0 15px 0 15px;">world</td>
    <td style="padding:0 15px 0 15px;">how</td>
    <td style="padding:0 15px 0 15px;">are</td>
    <td style="padding:0 15px 0 15px;">you?</td>
</tr>
<tr>
    <td style="padding:0 15px 0 15px;">hello</td>
    <td style="padding:0 15px 0 15px;">world</td>
    <td style="padding:0 15px 0 15px;">how</td>
    <td style="padding:0 15px 0 15px;">are</td>
    <td style="padding:0 15px 0 15px;">you?</td>
</tr>
</table>

Css

table td{
   border : 1px solid black;
   border-spacing: 1em 0;
 }

fiddle

like image 849
Ancient Avatar asked Oct 25 '25 08:10

Ancient


2 Answers

If I use the cellspacing css property it does it between both rows and columns.

There is no cellspacing CSS property.

The property is called border-spacing and …

The lengths specify the distance that separates adjoining cell borders. If one length is specified, it gives both the horizontal and vertical spacing. If two are specified, the first gives the horizontal spacing and the second the vertical spacing. Lengths may not be negative.

… takes two values.

So:

border-spacing: 1em 0;
like image 157
Quentin Avatar answered Oct 27 '25 00:10

Quentin



table {

    border-collapse: separate;
    border-spacing: 1em 0;

}

https://www.w3schools.com/cssref/pr_border-spacing.asp

like image 31
EverestOnline Marketing Avatar answered Oct 27 '25 00:10

EverestOnline Marketing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!