week7-Ch8
week7-Ch8
CHAPTER 8
TABLES
<tr>
Contains a table row
<td>
Contains a table cell
<caption>
Configures a description of the table
5
Copyright © Terry Felke-Morris http://terrymorris.net
<head> HTML
<style>
table, td { border: 1px solid black; }
</style>
Table Example
</head>
…
<table>
<caption>Bird Sightings</caption>
<tr>
<td>Name</td>
<td>Date</td>
</tr>
<tr>
<td>Bobolink</td>
<td>5/25/10</td>
</tr>
<tr>
<td>Upland Sandpiper</td>
<td>6/03/10</td>
</tr> DEMO
</table>
6
Copyright © Terry Felke-Morris http://terrymorris.net
<head>
<style>
table, td, th { border: 1px solid black; }
HTML
</style>
</head>
Table Example 2
…
<table>
<tr> Using the <th> Element
<th>Name</th>
<th>Birthday</th>
</tr>
<tr>
<td>James</td>
<td>11/08</td>
</tr>
<tr>
<td>Karen</td>
<td>4/17</td>
</tr>
<tr>
<td>Sparky</td>
<td>11/28</td>
</tr>
</table>
DEMO
7
Copyright © Terry Felke-Morris http://terrymorris.net
HTML Table Attributes
•align (obsolete)
•bgcolor (obsolete)
•border
•cellpadding (obsolete)
•cellspacing (obsolete)
•summary (obsolete but may be reinstated)
•width (obsolete)
8
Copyright © Terry Felke-Morris http://terrymorris.net
HTML Common Table Cell Attributes
•align (obsolete)
•bgcolor (obsolete)
•colspan
•rowspan
•valign (obsolete)
•height (deprecated)
•width (deprecated)
9
Copyright © Terry Felke-Morris http://terrymorris.net
<head>
<style>
HTML colspan
table, td { border: 1px solid black; }
</style>
Attribute
</head>
…
<table>
<tr>
<td colspan=“2”>
Birthday List</td>
</tr>
<tr>
<td>James</td>
<td>11/08</td>
</tr>
<tr>
<td>Karen</td>
<td>4/17</td>
</tr> DEMO
</table>
10
Copyright © Terry Felke-Morris http://terrymorris.net
HTML rowspan Attribute
<table>
<tr>
<td rowspan="2">This spans two rows</td>
<td>Row 1 Column 2</td>
</tr>
<tr>
<td>Row 2 Column 2</td>
</tr>
</table>
DEMO
11
Copyright © Terry Felke-Morris http://terrymorris.net
Accessibility and Tables
Use table header elements (<th> tags) to indicate column or row
headings.
Use the caption element to provide a text title or caption for the
table.
Complex tables:
Associate table cell values with their corresponding headers
◦ <th> tag id attribute
◦ <td> tag headers attribute
bgcolor background-color
cellpadding padding
height height
valign vertical-align
width width
-- background-image
16
examples/columnHeaders.html
inline styles
17
examples/rowHeaders.html
18
• The padding property specifies the amount of
space between a cell's content and the border of
that cell.
• The border-spacing property specifies the
space between cells.
• Don't like the double lines that make up a cell's
border?
19
border-collapse
• Internet Explorer does not support the
border-spacing property
• Another solution is to use the border-
collapse property. We can set border-
collapse to collapse so that the browser
will not render any border spacing.
• In your table rule, replace the border-
spacing declaration with the following:
border-collapse: collapse;
• Now it will render properly in IE as well!
20
• At times, we might have data cells that will
need to span across more than one column
or row.
21
rowspan & colspan Examples
22
examples/rowSpan.html
23
examples/colSpan.html
24
examples/combinedSpan.html
25
SUMMARY ATTRIBUTE
(will not validate at W3C)
alternatives
(i.e., your files that use tables should validate using the W3C validator)!!!