Space between cells but not on the border of the table?

J

Jan Aagaard

I have a simple table

+---+---+
| A | B |
+---+---+
| C | D |
+---+---+

And would like to have space between the cells, but not on the border
of the table.

If I add cellspacing or cellpadding to the table I get something like
this:

+-+---+-+---+-+
+-+---+-+---+-+
| | A | | B | |
+-+---+-+---+-+
+-+---+-+---+-+
| | C | | D | |
+-+---+-+---+-+
+-+---+-+---+-+

But what I would really like is this:

+---+-+---+
| A | | B |
+---+-+---+
+---+-+---+
| C | | D |
+---+-+---+

Is it possible to achieve that by only applying styles to the
<table>-element and not the individual <td>-elements? Perhaps using
<tbody> and <colgroup>?

I know it would be possible by adding right padding to A and C and
bottom padding to A and B, but I would like a general rule for the
table.

Another solution would be to add empty cells and use them as spacers,
but that adds a lot of extra cells if my table is larger than 2 x 2.

(Sorry about the ASCII graphics.)
 
W

windandwaves

Jan said:
I have a simple table

+---+---+
+---+---+

And would like to have space between the cells, but not on the border
of the table.

If I add cellspacing or cellpadding to the table I get something like
this:

+-+---+-+---+-+
+-+---+-+---+-+
+-+---+-+---+-+
+-+---+-+---+-+

But what I would really like is this:

+---+-+---+
+---+-+---+

Is it possible to achieve that by only applying styles to the
<table>-element and not the individual <td>-elements? Perhaps using
<tbody> and <colgroup>?

I know it would be possible by adding right padding to A and C and
bottom padding to A and B, but I would like a general rule for the
table.

Another solution would be to add empty cells and use them as spacers,
but that adds a lot of extra cells if my table is larger than 2 x 2.

If you make the first column a TH then you can add right padding to all the
other cells (or left, I am not 100% sure that I understand your question).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top