Back to the index.
On this page I explain some of the new CSS declarations to be used with tables.
This is 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.
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 table has empty-cells: show
by default. It should display the border of the
empty cell, but doesn't in IE7-.
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 |
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 |
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: width
s 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 |
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 |