TABLE Alignment

TABLE Alignment

Row 1 duck Cell 3 duck Cell 5
Row 2 duck Cell 4
Row 3
spacer 2

TABLE Alignment

Properly aligning your tables on your pages only relates to an appearance issue and does not affect the use of the data in the tables.

Table alignment is handled in several ways in HTML. If you set up the page style in a CSS document, you can manage the alignment with the CSS elements. I won't get into the use of CSS in this tutorial, but will continue to mention where I use it to reduce redundant styles to save a lot of typing. Other ways to align your tables on your page are the use of the "align" attribute in the <table>, <tr>, <th> and <td> elements.

The "align" attribute has the same attribute values for all of the elements. It gives you options for aligning your tables, data text or images in the center or on the left or right in the page, table, row or cell. The following example will show some application of the alignments for your tables and data.  One thing to remember about the "align" attribute is that it will align EVERYTHING in the direction designated by the attribute value (left, right, center, justify).

Example 1 Aligning your tables and data

<tr>
  <td align="center">
    <table width="600" border="7" style="border-color:#900" cellpadding="5">
      <tr class="trtext1">
        <td width="60%" align="center">File Name</td>
        <td width="40%" align="center">Submitter</td>
      </tr>
      <tr bgcolor="#FFFF99">
        <td align="left">File for research purposes</td>
        <td align="center">Bryant Walker</td>
      </tr>
    </table>
  </td>
</tr>
File Name Submitter
File for research purposes Bryant Walker
<tr>
  <td align="left">
    <table width="600" border="7" style="border-color:#900" cellpadding="5">
      <tr class="trtext1">
        <td width="60%" align="right">File Name</td>
        <td width="40%" align="right">Submitter</td>
      </tr>
      <tr bgcolor="#FFFF99">
        <td align="left">File for research purposes</td>
        <td align="center">Bryant Walker</td>
      </tr>
    </table>
  </td>
</tr>
File Name Submitter
File for research purposes Bryant Walker
<tr>
  <td>
    <table width="600" align="right" border="7" style="border-color:#900" cellpadding="5">
      <tr class="trtext1">
        <td width="60%" align="left">File Name</td>
        <td width="40%" align="left">Submitter</td>
      </tr>
      <tr> bgcolor="#FFFF99">
        <td align="left">File for research purposes</td>
        <td align="center">Bryant Walker</td>
      </tr>
    </table>
  </td>
</tr>
File Name Submitter
File for research purposes Bryant Walker

The alignment for the first table is defined in the <td> element box which contains the table.  It centers the table in the box.  Also, the table headers are centered in the data cells by the "align" attribute in the <td> element.  The second table is aligned to the left by the <td> element box which contains the table.  Notice that I changed the header text alignment in the <td> element header cells to demonstrate that you can align the text in a cell on the left, right or in the center.  The last table is aligned to the right in the <td> element box, not by the <td> box, but by adding the "align" attribute to the <table> element.  You can do it either way, but there may come a time when one does not work because the other is in control of alignment.  I also moved the header text to the left with the "align" attribute.


Previous Page Next Page