HTML and CSS Reference
In-Depth Information
The following example creates a simple table that shows the results achieved by three students on their math exam.
<table border="1">
<tr>
<th>Pupil</th>
<th>Result</th>
</tr>
<tr>
<td>James</td>
<td>85</td>
</tr>
<tr>
<td>Alicia</td>
<td>97</td>
</tr>
<tr>
<td>Tom</td>
<td>76</td>
</tr>
</table>
The border attribute on the <table> tag adds a 1-pixel border to the table so that we can see the rows and
columns clearly. The first row contains two <th> elements that make up the column headings; browsers will usually
display these in bold text by default. We then define the records by creating three separate rows, each containing two
<td> elements (table cells), one for the pupil's name and the one for his or her exam result. Figure 4-8 shows this
table displayed in a browser.
Figure 4-8 A table of exam results.
Table Cell Attributes
Both <td> and <th> elements have a number of attributes that can be used to help format them. One example is
the colspan (column span) attribute. Use the colspan attribute in instances where you need a particular table
cell to span multiple columns. The following example uses the colspan attribute to create a cell that spans the
whole table.
<table border="1">
<tr>
<th colspan="2">Class 2B</th>
</tr>
<tr>
Search WWH ::




Custom Search