See also the W3C tables specification.
On this page I explain some of the new CSS declarations to be used with tables.
| Value | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b4 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.5b | Konqueror 3.5.7 |
|---|---|---|---|---|---|---|---|---|---|---|
| Show or hide empty cells in table | No | Yes | Yes | Yes | Yes | |||||
IE7- uses show as default, IE8b1 hide. Changing
the default is not possible, though. |
||||||||||
| Fit cells snugly | Incom |
Yes | Yes | Yes | Yes | Yes | ||||
|
In IE7- |
||||||||||
| cellspacing | No | Yes | Yes | Yes | Yes | Yes | ||||
Really strict width for tables
|
Yes | Yes | Yes | Yes | Yes | |||||
| At which side should the caption appear? | No | Yes | Yes+ | Yes | Yes | Yes | ||||
Mozilla also supports the extra values left and right. |
||||||||||
| Value | IE 5.5 | IE 6 | IE 7 | IE8b1 | FF 2 | FF 3b4 | Saf 3.0 Win | Saf 3.1 Win | Opera 9.5b | Konqueror 3.5.7 |
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |
The default table with only a border defined for the TDs. Note the space between the TDs: as has been the case since the invention of tables, the default cellspacing is 1.
The table has empty-cells: show by default. It should display the border of the
empty cell, but doesn't in IE7-.
We're going to add one style declaration per example, unless otherwise noted, and see what happens in the various browsers.
empty-cells is not supported by Explorer Windows. However, its default is hide
so that it accidentally gets this test right.
This declaration takes two values:
show: show empty cells (with a border). This is the default.hide: hide empty cells.<table style="empty-cells: show">
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |
<table style="empty-cells: hide">
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |
Not supported by Explorer Mac.
In Explorer Windows border-collapse: collapse does not overrule cellspacing.
This declaration takes two values:
separate: keep borders separate. This is the default.collapse: merge borders of adjoining cells.<table style="border-collapse: collapse">
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |
border-collapse: collapse should overrule cellspacing. The example below
should look the same as the previous one.
<table style="border-collapse: collapse;" cellspacing="10">
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |
Not supported by Explorer.
border-spacing is cellspacing translated to CSS. Note that it needs a unit.
<table style="border-spacing: 10px;">
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |
You can use two values: the first is the horizontal cellspacing, the second the vertical one.
<table style="border-spacing: 40px 10px;">
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |
table-layout takes two values:
auto: the table is layed out normally (see below). This is the default value.fixed: the table obeys the width, even if it normally wouldn't.Let's give the test table a width. This width is far too narrow to normally show all content,
and therefore the table stretches up beyond the 100px. This is normal behaviour: widths on tables
have always been more like a polite advice than a strict rule. If the table needs more space than the width
allows, it takes more space.
<table style="width: 100px;">
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |
If we add table-layout: fixed, however, the table obeys the width, even if that
results in unreadable content.
<table style="table-layout: fixed; width: 100px;">
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |
Not supported by Explorer Windows.
Mozilla supports two extra values.
caption-side takes four values, even though W3C specifies only the first two:
top. This is the default.bottom. This is the other official value.left. Mozilla extension.right. Mozilla extension.<caption style="caption-side: bottom">
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |
<caption style="caption-side: right">
| First TD of first TR | Second TD of first TR | Third TD of first TR |
| First TD of second TR | Third TD of second TR |