Section G.2. Basic XHTML Tables


G.2. Basic XHTML Tables

Tables are used to organize data in rows and columns. Our first example (Fig. G.1) creates a table with six rows and two columns to display price information for fruit.

Figure G.1. XHTML table.

  1  <?xml version = "1.0"?>  2  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"  3     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">  4  5  <!-- Fig. G.1: table1.html -->  6  <!-- Creating a basic table -->  7  8  <html xmlns = "http://www.w3.org/1999/xhtml">  9     <head> 10        <title>A simple XHTML table</title> 11     </head> 12 13     <body> 14 15        <!-- the <table> tag opens a table --> 16        <table border = "1" width = "40%"                   17           summary = "This table provides information about 18              the price of fruit" >                         19 20           <!-- the <caption> tag summarizes the table's    --> 21           <!-- contents (this helps the visually impaired) --> 22           <caption><strong>Price of Fruit</strong></caption> 23 24           <!-- the <thead> is the first section of a table --> 25           <!-- it formats the table header area            --> 26           <thead>              27              <tr>              <!-- <tr> inserts a table row --> 28                 <th>Fruit</th> <!-- insert a heading cell --> 29                 <th>Price</th> 30              </tr>             31           </thead>             32 33           <!-- the <tfoot> is the last section of a table --> 34           <!-- it formats the table footer                --> 35           <tfoot>                 36              <tr>                 37                 <th>Total</th>    38                 <bi<th>$3.75</th> 39              </tr>                40           </tfoot>                41 42           <!-- all table content is enclosed --> 43           <!-- within the <tbody>            --> 44           <tbody>              45              <tr>              46                 <td>Apple</td> <!-- insert a data cell --> 47                 <td>$0.25</td> 48              </tr>             49 50              <tr> 51                 <td>Orange</td> 52                 <td>$0.50</td> 53              </tr> 54 55              <tr> 56                 <td>Banana</td> 57                 <td>$1.00</td> 58              </tr> 59 60              <tr> 61                 <td>Pineapple</td>\ 62                 <td>$2.00</td> 63              </tr> 64           </tbody>             65 66        </table> 67 68     </body> 69  </html> 

Tables are defined with the table element (lines 1666). Lines 1618 specify the start tag for a table element that has several attributes. The border attribute specifies the table's border width in pixels. To create a table without a border, set border to "0". This example assigns attribute width the value "40%" to set the table's width to 40 percent of the browser's width. A developer can also set attribute width to a specified number of pixels. Try resizing the browser window to see how the width of the window affects the width of the table.

As its name implies, attribute summary (lines 1718) describes the table's contents. Speech devices use this attribute to make the table more accessible to users with visual impairments. The caption element (line 22) describes the table's content and helps textbased browsers interpret the table data. Text inside the <caption> tag is rendered above the table by most browsers. Attribute summary and element caption are two of the many XHTML features that make Web pages more accessible to users with disabilities.

A table has three distinct sectionshead, body and foot. The head section (or header cell) is defined with a thead element (lines 2631), which contains header information such as column names. Each tr element (lines 2730) defines an individual table row. The columns in the head section are defined with th elements. Most browsers center text formatted by th (table header column) elements and display them in bold. Table header elements are nested inside table row elements.

The foot section (lines 3540) is defined with a tfoot (table foot) element. The text placed in the footer commonly includes calculation results and footnotes. Like other sections, the foot section can contain table rows, and each row can contain columns.

The body section, or table body, contains the table's primary data. The table body (lines 4464) is defined in a tbody element. In the body, each tr element specifies one row. Data cells contain individual pieces of data and are defined with TD (table data) elements within each row.



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net