TD Sizing

To get the width or height of a table data cell you use offsetWidth and offsetHeight but the values of cellpadding, cellspacing, and wether a border or width is stated will have an affect on the results.

This first example shows a table with no width stated, its cellpadding,cellspacing, and border are initially set to zero.
The table has 2 rows, the first row has 3 td cells while the second row has 2 td cells (the first cell is spanned across the second cell).

When border, cellpadding, or cellspacing is selected 5px is added respectively

Border 0px 5px
Cellpadding 0px 5px
Cellspacing 0px 5px

Results:




Cell 1 content Cell 2 content Cell 3 content
Cell 4 content Cell 5 content


Summary:

Border = 0

Cellpadding = 0 Cellspacing = 0
88 88 88
176 88

Cellpadding = 1 Cellspacing = 0
98 98 98
196 98

Cellpadding = 0 Cellspacing = 1
88 88 88
181 88

Cellpadding = 1 Cellspacing = 1
98 98 98
201 98

Border = 1

Cellpadding = 0 Cellspacing = 0
90 90 90
180 90

Cellpadding = 1 Cellspacing = 0
100 100 100
200 100

Cellpadding = 0 Cellspacing = 1
90 90 90
185 90

Cellpadding = 1 Cellspacing = 1
100 100 100
205 100

Conclusion:

When a border is used 1px is added to each side of the td cell.
Cellpadding is added to each side of the td cell.
Cellspacing does not affect individual td cell size.

But ... if a cell is spanned

The border and cellpadding for each spanned td cell is added.
The cellspacing between each spanned cell is added


This second example shows the table with a fixed width of 264px (to match the above tables default size), its cellpadding,cellspacing, and border are initially set to zero.

When border, cellpadding, or cellspacing is selected 5px is added respectively

Border 0px 5px
Cellpadding 0px 5px
Cellspacing 0px 5px

Results:




Cell 1 content Cell 2 content Cell 3 content
Cell 4 content Cell 5 content


Summary:

Border = 0

Cellpadding = 0 Cellspacing = 0
88 88 88
176 88

Cellpadding = 1 Cellspacing = 0
88 88 88
176 88

Cellpadding = 0 Cellspacing = 1
82 81 81
168 81

Cellpadding = 1 Cellspacing = 1
82 81 81
168 81

Border = 1

Cellpadding = 0 Cellspacing = 0
84 85 85    moz shows 85 85 84
169 85                          170 84

Cellpadding = 1 Cellspacing = 0
84 85 85
169 85

Cellpadding = 0 Cellspacing = 1
78 78 78
161 78

Cellpadding = 1 Cellspacing = 1
78 78 78
161 78

Conclusion:

If the width of the table does not divide equally between the columns IE will tend to make the all but the first column equal, the first column will be the unequal remainder.
Moz on the other hand does the opposite and makes all but the last column equal applying the unequal remainder to the last cell

When a border is used its width is divided by the number of columns and deducted from each column.
Cellpadding does not affect the width.
Cellspacing is deducted from the individual column.

But ... if a cell is spanned

Still under revision

Notes to self;

When a fixed width is used for the table the height adjusts to compensate.
The above only gives examples referring to the width of a column, the same would apply to the row height.
Still have to see what happens with a table with a fixed width and height, should be fun :)