| Overview |
| |
In this chapter you will learn
- How to create tables in an XHTML document
- Adding heading and text in a table
- Adding colors to a table
- How to format a table
- Use of col and colgroup tag
|
| |
| Introduction |
| |
Information presented in a tabular form is more popular than when they are displayed in paragraph form. Data arranged in a table is easy to understand, utilize and recollect. Tables contain headings, rows and columns that simplify the otherwise cumbersome information and display the data with greater clarity. Tables are used to create lists as well as to find other elements in a page or other pages.
This chapter elaborates the concept of tables, their creation and customization. XHTML tables empower users to arrange data into tables; in the form of text, images, and forms etc. with the help of rows and columns.
The designing and usage of tables in XHTML is more or less similar to the usage of tables in HTML. A small difference is that some attributes of some tags are not applicable in XHTML.
Several tags can be used to make tables in a web page. They are:
|
| |
Table Tag
The <table> tag defines a table. Table headers, table rows, table cells and other tables can be put inside a <table> tag.
The “align” and “bgcolor” attributes of the <table> tag in HTML have been are not supported in XHTML.
Attributes of Table Tag
Border
Border establishes the size of the border surrounding the table. The default value is 0, which means there is no border at all. If border is without a value, the default is 1.
| Example |
| <table border=2> </table> |
| |
Cellpadding
Cellpadding sets the amount of space between the cell walls and the contents. The default value for cellpadding is 1.
| Example |
| <table border=2 cellpadding=4> </table> |
| |
Cellspacing
Cellspacing sets the amount of space between the cells of a table. If the borders are visible, cellspacing controls the width of internal borders.
| Example |
| <table border=3 cellspacing=3> </table> |
| |
Width
Width sets the width of the table. It can be expressed either as an absolute value in pixels, or as a percentage of screen width.
| Example |
| <table border=2 width=70%> </table> |
| |
Background
Background sets the background image for the table.
| Example |
| <table border=1 background=”myimage.gif”> </table> |
| |
Bordercolor
Bordercolor sets the color of all the borders of the table.
| Example |
| <table border=5 bordercolor=red> </table> |
| |
Tr Tag
The <tr> tag is the table row tag. It designates a table row in the table. Each <tr> tag contains one or more <td> or <th> elements. It works in a similar way as it does in HTML. The “bgcolor” attribute of the <tr> tag has been deprecated in XHTML.
Example |
<table border=2> |
<tr> <td>cricket jokes</td> <td> tennis jokes</td> <td>golf jokes</td> </tr> |
<tr> <td>classic jokes</td> <td>soft jokes</td> <td>political jokes</td> </tr> |
</table> |
| |
|