Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add space between two particular <td>s

I have a table

<tr>
   <td>One</td>
   <td>Two</td>
   <td>Three</td>
   <td>Four</td>
</tr>

How can I add some space between the <td>s 'Two' and 'Three' alone?

like image 726
Shalin Avatar asked Nov 10 '12 06:11

Shalin


People also ask

How do I add space between two TD elements?

The space between two rows in a <table> can be added by using the CSS border-spacing and border-collapse properties. The border-spacing property is used to set the spaces between cells of a table, and the border-collapse property specifies whether the border of the table is collapsed or not.

How do I give a space between two elements in the same div?

Margins - Outer Spacing It's used to add spacing between an element and another. For example, in the previous example, I added margin-bottom: 1rem to add vertical spacing between the two stacked elements.


3 Answers

my choice was to add a td between the two td tags and set the width to 25px. It can be more or less to your liking. This may be cheesy but it is simple and it works.

like image 57
nik Avatar answered Oct 27 '22 13:10

nik


The simplest way:

td:nth-child(2) {
    padding-right: 20px;
}​

But that won't work if you need to work with background color or images in your table. In that case, here is a slightly more advanced solution (CSS3):

td:nth-child(2) {
    border-right: 10px solid transparent;
    -webkit-background-clip: padding;
    -moz-background-clip: padding;
    background-clip: padding-box;
}

It places a transparent border to the right of the cell and pulls the background color/image away from the border, creating the illusion of spacing between the cells.

Note: For this to work, the parent table must have border-collapse: separate. If you have to work with border-collapse: collapse then you have to apply the same border style to the next table cell, but on the left side, to accomplish the same results.

like image 23
Hubro Avatar answered Oct 27 '22 14:10

Hubro


None of the answers worked for me. The simplest way would be to add <td>s in between with width = 5px and background='white' or whatever the background color of the page is.

Again this will fail in case you have a list of <th>s representing table headers.

like image 36
saran3h Avatar answered Oct 27 '22 15:10

saran3h