MODULE -II(Tables)
MODULE -II(Tables)
TABLES
Introducing Tables
Tables display information in rows and columns; they are commonly
used to display all manner of data that fits in a grid such as train
schedules, television listings, financial reports, and sports results.
You can think of a table as being very similar to a spreadsheet.
Introducing Tables
Each rectangle is known as a cell. A row is made up of a set of cells on
the same line from left to right, and a column is made up of a line of
cells going from top to bottom.
Here is the code that was used to create this basic table
Introducing Tables
Created a table in XHTML using the <table> element. Inside the
<table> element, the table is written out row by row.
A row is contained inside a <tr> element — which stands for table
row.
Each cell is then written inside the row element using a <td>
element — which stands for table data.
This time the table includes headings. In this example, the table
shows a financial summary for a small company.
Introducing Tables
Introducing Tables
In each row, the first cell is also a table heading cell (indicated using a
<th>), which states which quarter the results are for.
Then the remaining three cells of each row contain table data and are
contained inside the <td> elements.
Basic Table Elements and Attributes
Some of the attributes allow you to create more sophisticated table layouts.
The <table> Element Creates a Table
The <table> element is the containing element for all tables. It can carry the
following attributes:
All the universal attributes
Basic event attributes for scripting
The <table> element can carry the following deprecated attributes. Even
though they are deprecated, you will still see many of them in use today:
align bgcolor border cellpadding cellspacing dir frame rules summary width
Basic Table Elements and Attributes
the <td> and <th> elements can also carry the following attributes:
abbr align axis bgcolor char charoff colspan headers
height nowrap rowspan scope valign width
The abbr Attribute
The abbr Attribute
The abbr attribute is used to provide an abbreviated version of the cell’s
content.
abbr="description of services"
The <td> and <th> Elements Represent Table Cells
The align Attribute
The align attribute sets the horizontal alignment for the content of the cell.
align="alignment“
The possible values for the align attribute are left, right, center, justify, and
char, each of which was described earlier in “The < tr >
The colspan Attribute
The colspan attribute is used when a cell should span across more than one
column.
The value of the attribute specifies how many columns of the table a cell
will span across
colspan="2"
The <td> and <th> Elements Represent Table Cells
The rowspan Attribute
The rowspan attribute specifies the number of rows of the table a cell
will span across, the value of the attribute being the number of rows the
cell stretches across.
rowspan="2“
Adding a <caption> to a Table
Even if the surrounding text describes the content of the table, it is
good practice to give the table a formal caption using the <caption>
element.
By default, most browsers will display the contents of this element
centered above the table,
The <caption> element appears directly after the opening <table> tag;
it should come before the first row.
<table>
<caption> Opening hours for the Example Cafe</caption>
<tr>
Grouping Sections of a Table
some techniques that allow you to group together cells, rows, and
columns of a table, and learn the advantages that doing this can bring.
In particular, you will see how to do the following:
Use the rowspan and colspan attributes to make cells stretch over more
than one row or column.
Split a table into three sections: a head, body, and foot
Group columns using the <colgroup> element
Grouping Sections of a Table
If two or more columns are related, you can use the <colgroup>
element to explain that those columns are grouped together.
The first four columns are in the first column group, and the next
two columns are in the second column group.
Grouping Columns Using the <colgroup>
Element
When the <colgroup> element is used, it comes directly after the
opening <table> tag and carries a span attribute, which is used to
indicate how many columns the group contains.
The class attribute is used to attach CSS rules that tell the browser
the width of each column in the group and the background color for
each cell.
Grouping Columns Using the <colgroup> Element
Nested Tables
you can even place another entire table inside a table cell, creating
what’s called a nested table.