J.10. Basic XHTML Tables

This section presents the XHTML tablea frequently used feature that organizes data into rows and columns. Our first example (Fig. J.10) uses a table with six rows and two columns to display price information for fruit.

Figure J.10. XHTML table.

(This item is displayed on pages 1344 - 1345 in the print version)

"http://www.w3.org/1999/xhtml"> 9 10

 1  "1.0"?>
 2  "-//W3C//DTD XHTML 1.1//EN"
 3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 4
 5 
 6 
 7
 8 
Creating a basic table 11 12 13 14 15 16 "1"width ="40%" 17 summary ="This table provides information about 18 the price of fruit"> 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
Price of Fruit
Fruit Price
Apple $0.25
Orange $0.50
Banana $1.00
Pineapple $2.00
Total $3.75
66 67 68


Tables are defined with the table element. 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 "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.


As its name implies, attribute summary (line 17) 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 text-based browsers interpret the table data. Text inside the tag is rendered above the table by most browsers. Attribute summary and element caption are two of many XHTML features that make Web pages more accessible to users with disabilities.


Error-Prevention Tip J.1

Try resizing the browser window to see how the width of the window affects the width of the table.

 

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 it in bold. Table header elements are nested inside table row elements.


The body section, or table body, contains the table's primary data. The table body (lines 3454) is defined in a tbody element. Data cells contain individual pieces of data and are defined with td (table data) elements.

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






C++ How to Program
C++ How to Program (5th Edition)
ISBN: 0131857576
EAN: 2147483647
Year: 2004
Pages: 627
Simiral book on Amazon

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