J.11. Intermediate XHTML Tables and Formatting

In the previous section, we explored the structure of a basic table. In Fig. J.11, we enhance our discussion of tables by introducing elements and attributes that allow the document author to build more complex tables.

Figure J.11. Complex XHTML table.

(This item is displayed on pages 1346 - 1348 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">
Intermediate table design 11 12 13 14 15

Table Example Page

16 17 "1"> 18 19 20 21 22 23 24 25 26 "right"span ="1"/> 27 28 29 30 31 32 33 34 35 36 40 41 42 46 47 48 "bottom"> 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
Here is a more complex sample table.
"2"> 37 "camel.gif" width = "205" 38 height = "167" alt = "Picture of a camel" /> 39 "4" valign = "top"> 43

Camelid comparison


Approximate as of 9/2002

# of Humps Indigenous region Spits? Produces Wool?
Camels (bactrian) 2 Africa/Asia "2">Llama "2">Llama
Llamas 1 Andes Mountains
76 77 78

Common Programming Error J.5

When using colspan and rowspan to adjust the size of table data cells, keep in mind that the modified cells will occupy more than one column or row; other rows or columns of the table must compensate for the extra rows or columns spanned by individual cells. If you do not, the formatting of your table will be distorted, and you could inadvertently create more columns and rows than you originally intended.


The table begins at line 17. Element colgroup (lines 2227) groups and formats columns. The col element (line 26) specifies two attributes in this example. The align attribute determines the alignment of text in the column. The span attribute determines how many columns the col element formats. In this case, we set align's value to "right" and span's value to "1" to right-align text in the first column (the column containing the picture of the camel in the sample screen capture).

Table cells are sized to fit the data they contain. Document authors can create larger data cells by using attributes rowspan and colspan. The values assigned to these attributes specify the number of rows or columns occupied by a cell. The th element at lines 3639 uses the attribute rowspan ="2" to allow the cell containing the picture of the camel to use two vertically adjacent cells (thus the cell spans two rows). The th element at lines 4245 uses the attribute colspan ="4" to widen the header cell (containing Camelid comparison and Approximate as of 9/2002) to span four cells.

Line 42 introduces attribute valign, which aligns data vertically and may be assigned one of four values"top" aligns data with the top of the cell, "middle" vertically centers data (the default for all data and header cells), "bottom" aligns data with the bottom of the cell and "baseline" ignores the fonts used for the row data and sets the bottom of all text in the row on a common baseline (i.e., the horizontal line to which each character in a word is aligned).

Introduction to Computers, the Internet and World Wide Web

Introduction to C++ Programming

Introduction to Classes and Objects

Control Statements: Part 1

Control Statements: Part 2

Functions and an Introduction to Recursion

Arrays and Vectors

Pointers and Pointer-Based Strings

Classes: A Deeper Look, Part 1

Classes: A Deeper Look, Part 2

Operator Overloading; String and Array Objects

Object-Oriented Programming: Inheritance

Object-Oriented Programming: Polymorphism


Stream Input/Output

Exception Handling

File Processing

Class string and String Stream Processing

Web Programming

Searching and Sorting

Data Structures

Bits, Characters, C-Strings and structs

Standard Template Library (STL)

Other Topics

Appendix A. Operator Precedence and Associativity Chart

Appendix B. ASCII Character Set

Appendix C. Fundamental Types

Appendix D. Number Systems

Appendix E. C Legacy Code Topics

Appendix F. Preprocessor

Appendix G. ATM Case Study Code

Appendix H. UML 2: Additional Diagram Types

Appendix I. C++ Internet and Web Resources

Appendix J. Introduction to XHTML

Appendix K. XHTML Special Characters

Appendix L. Using the Visual Studio .NET Debugger

Appendix M. Using the GNU C++ Debugger


show all menu

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

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