mozilla

Revision 105938 of Tables

  • Revision slug: Useful_CSS_tips/Tables
  • Revision title: Tables
  • Revision id: 105938
  • Created:
  • Creator: Lombardp
  • Is current revision? No
  • Comment

Revision Content

Borders

This is a standard table with non-zero cellspacing and 1px cell borders.

Table with cellspacing="4"
cell content cell content cell content
cell content cell content cell content
cell content cell content cell content

If you want to transform the table in a grid, you set cellspacing to 0 and the rendered tables is this.

Table with cellspacing="0"
cell content cell content cell content
cell content cell content cell content
cell content cell content cell content

The result is not as expected and the reason is that the default border model is set to separate: with this model each cell has its own border, also if cells sapcing is zero. In order to have a grid-like rendering, the collapse border model has to be set.

Table with cellspacing="0"
and border-collapse:collapse;
cell content cell content cell content
cell content cell content cell content
cell content cell content cell content

Fixed header

If a table contain a lot of rows, when the user has to scroll down to see all data, table header row scrolls up and becomes invisibile. You can have a table with fixed header and vertical scrolling, use the following code.

(to be written)

Revision Source

<p>
</p>
<h3 name="Borders"> Borders </h3>
<p>This is a standard table with non-zero cellspacing and 1px cell borders.
</p>
<table cellspacing="4">
<tbody><tr><td colspan="3" style="border: 1px solid black;">Table with cellspacing="4"</td></tr>
<tr><td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td></tr>
<tr><td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td></tr>
<tr><td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td></tr>
</tbody></table>
<p>If you want to transform the table in a grid, you set cellspacing to 0 and the rendered tables is this.
</p>
<table cellspacing="0">
<tbody><tr><td colspan="3" style="border: 1px solid black;">Table with cellspacing="0"</td></tr>
<tr><td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td></tr>
<tr><td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td></tr>
<tr><td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td></tr>
</tbody></table>
<p>The result is not as expected and the reason is that the default border model is set to <b>separate</b>: with this model each cell has its own border, also if cells sapcing is zero. In order to have a grid-like rendering, the <b>collapse</b> border model has to be set.
</p>
<table cellspacing="0" style="border-collapse:collapse;">
<tbody><tr><td colspan="3" style="border: 1px solid black;">Table with cellspacing="0" <br>and border-collapse:collapse;</td></tr>
<tr><td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td></tr>
<tr><td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td></tr>
<tr><td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td>
    <td style="border: 1px solid black;">cell content</td></tr>
</tbody></table>
<h3 name="Fixed_header"> Fixed header </h3>
<p>If a table contain a lot of rows, when the user has to scroll down to see all data, table header row scrolls up and becomes invisibile. You can have a table with fixed header and vertical scrolling, use the following code.
</p><p>(to be written)
</p>
Revert to this revision