22.3. Borders
There are two models for handling borders in CSS 2.1. In one, the borders around
Values:collapse separate inherit Initial value:collapse Applies to:table and inline-table elements Inherited:Yes 22.3.1. The Separated Borders Model
In the separated borders model , the border is drawn on all four sides of each cell (or as specified by the border properties), and an amount of space can be added between cells with the
Values:<length> <length>? inherit Initial value:Applies to:table and inline-table elements Inherited:Yes The values for border-spacing are two length measurements. The horizontal spacing value comes first and is applied between the cells in each row of the table. The vertical value always comes second and is applied between cells in each column. If you provide just one value, it will be applied both horizontally and vertically. The table in Figure 22-4 uses the separated border model.
table {
border-collapse: separate;
border-spacing: 10px 3px;
border: none;}
td { border: 1px solid black; }
Figure 22-4. A table with border-spacing
The default value for
border-spacing
is 0, which causes adjacent borders to touch,
When using the separated border model, rows, row groups,
If you have a few
Values:show hide inherit Initial value:show Applies to:Table cell elements Inherited:Yes The default value for empty-cells is show , which shows the background and borders for cells that do not contain any content. The hide value hides the cell's background and borders and is equivalent to visibility: hidden .
For a cell to be "empty," it may not contain any text or
Figure 22-5 shows the previous table border example, this time with empty elements set to hide .
table {border-collapse: separate;
border-spacing: 10px 3px;
empty-cells: hide;
border: none;}
td { border: 1px solid black; }
Figure 22-5. Empty cells hidden with the empty-cells property
22.3.2. The Collapsing Border ModelIn the collapsing border model , the borders of adjacent borders "collapse" so that only one of the borders is visible and extra space between borders is removed. Figure 22-6 shows the table from the previous examples, only this time, the border-collapse property has been set to collapse .
table {
border-collapse: collapse;
border: none;}
td { border: 1px solid black; }
Figure 22-6. A table with
|
|
If there can only be one border between each pair of cells, what happens when neighboring cells have conflicting border styles? The authors of CSS anticipated this problem and devised a system for resolving border conflicts.
Borders with
Borders with a style of
none
have the
Wider borders win over narrower ones, regardless of the border style.
If the neighboring borders are the same width, then it comes down to a battle of styles. The CSS 2.1 specification establishes this pecking order for border styles (in order from most to least precedence):
double
,
solid
,
dashed
,
If the border styles