Tables are defined with the <table> tag. A
table is divided into rows (with the <tr> tag), and each row is divided
into data cells (with the <td> tag). The letters td stands for table data,
which is the content of a data cell. A data cell can contain text, images,
lists, paragraphs, forms, horizontal rules, tables, etc.
This
Code
|
Would
Display
|
<table>
<tr> <td>row 1, cell 1</td> <td>row 1, cell
2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row
2, cell 2</td> </tr> </table>
|
row
1, cell 1
row
1, cell 2
row
2, cell 1
row
2, cell 2
|
Tables and the Border Attribute
To display a table with borders,
you will use the border attribute.
This
Code
|
Would
Display
|
||
<table
border="1"> <tr> <td>Row 1, cell 1</td>
<td>Row 1, cell 2</td> </tr> </table>
|
|
and....
This
Code
|
Would
Display
|
||
<table
border="5"> <tr> <td>Row 1, cell 1</td>
<td>Row 1, cell 2</td> </tr> </table>
|
|
Open up your text editor. Type in
your <html>, <head> and <body> tags. From here on I will only
be writing what goes between the <body> tags. Type in the following:
<table
border="1">
<tr>
<td>Tables can be used to
layout information</td>
<td> <img
src="http://profdevtrain.austincc.edu/html/graphics/chef.gif">
</td>
</tr>
</table>
Save
your page as mytable1.html and view it in your browser.
Headings in a Table
Headings in a table are defined
with the <th> tag.
This
code
|
Would
Display
|
||||||
<table
border="1"> <tr> <th>Heading</th>
<th>Another Heading</th> </tr>
<tr> <td>row 1, cell
1</td>
<td>row 1, cell 2</td>
</tr>
<tr> <td>row 2, cell
1</td> <td>row 2, cell 2</td> </tr> </table>
|
|
Cell Padding and Spacing
The <table> tag has two
attributes known as cellspacing and cellpadding. Here is a table example
without these properties. These properties may be used separately or together
.
This
Code
|
Would
Display
|
||||
<table
border="1"> <tr> <td>some text</td>
<td>some text</td> </tr> <tr> <td>some
text</td> <td>some text</td> </tr> </table>
|
|
Table Tags
Tag
|
Description
|
<table>
|
Defines
a table
|
<th>
|
Defines
a table header
|
<tr>
|
Defines
a table row
|
<td>
|
Defines
a table cell
|
<caption>
|
Defines
a table caption
|
<colgroup>
|
Defines
groups of table columns
|
<col>
|
Defines
the attribute values for one or more columns in a table
|
No comments:
Post a Comment