Lesson Practice 2-3:
Adding Structure with Tables
Task 1: Create a simple table with column headings
- Open your template.htm in notepad++.
- In the title element, add the title: Create a Simple Table
- Add an h1 element using the same text as in the title element.
- Add a table structure:
- On the line after the opening body tag, key the following, including the indents:
<table> |
|
|
|
<tr> |
|
|
|
<td>Row1 Col 1</td> |
|
|
<td>Row1 Col 2</td> |
|
|
<td>Row1 Col 3</td> |
|
</tr> |
|
|
<tr> |
|
|
|
<td>Row2 Col 1</td> |
|
|
<td>Row2 Col 2</td> |
|
|
<td>Row2 Col 3</td> |
|
</tr> |
|
|
<tr> |
|
|
|
<td>Row3 Col 1</td> |
|
|
<td>Row3 Col 2</td> |
|
|
<td>Row3 Col 3</td> |
|
</tr> |
|
</table> |
|
|
- Save in the Tables folder using the filename table1.htm then view in browser.
- Examine the table and the code, so you understand how the code for each row and cell works.
It is good practice to have each cell on a separate line, so the rows of code do not get so long and difficult to follow.
- Add a table heading row:
- Add five blank lines between the opening table tag and the first opening row tag.
- To create column heading row, key the following into the blank lines:
|
< tr> |
|
|
|
<th>Col 1</th> |
|
|
<th>Col 2</th> |
|
|
<th>Col 3</th> |
|
</tr> |
|
- Save again and view the result in the browser.
Task 2: Add a Border and Color
You will add some color and definition to this table using attributes, for now. Later you will change the formatting to use CSS styling.
- Open table1.htm in notepad++. Immediately save as table2.htm
- In the title element, change the title to: Adding Borders, Background Color and Sizing
- Change the text in the h1 element also.
- Add border and color:
- Add the border=" " attribute in the opening table tag, setting the border to 3 pixels. Save and preview.
- Change the border to 10 pixels. Save again and view. Experiment as you wish, and leave the border at either setting as you like.
- Add the bgcolor=" " attribute to the opening table tag, using the value gray.
- Add the bgcolor attribute to the opening row tag of the header row, using the value teal.
- Adjust table and cell sizes:
- Add height and width attributes to the opening table tag, setting them both to 200 pixels. View the page.
Note that the headings are automatically centered, and cell contents are automatically at the left of each cell and vertically centered.
Also, the height attribute may not distribute the rows evenly.
- To distribute the rows evenly, the first cell in each row must be given the same height. In the first opening header tag, add a height attribute set to 50.
- Add the same attribute and value to the opening <td> tag for the first cell in each row.
- Save and preview. The rows should be equal height now.
Exercise 3 – Column and Row Spanning
- Open table2.htm, if necessary, and immediately save as table3.htm
- In the title element, change the title to: Column and Row Spans
- Change the text in the h1 element also.
- Remove the cell spacing attribute from the table element. Save and view.
- Add a merged title row:
- Add a row between the opening table tag and the header row. Add one cell to this row. Between the <td> tags, add the text: How to Expand Rows and Columns. Save and view.
- To make this single cell go across the table, you must ‘span' the columns. In the opening tag of this cell, add the colspan=" " attribute with the value of 3. Save and view.
- Span rows and columns:
- Delete the entire first cell in the middle regular row (Row2 Col1).
- To the first cell in the first regular row (Row1 Col1), add the rowspan=" " attribute, set to 2. Save and view.
- Delete the entire last cell in the last row (Row3 Col3). (Keep the closing row tag.)
- To the opening tag of what is how the last cell (Row3 Col2), add the colspan attribute, set to 2. Save and view. The file should now appear similar to the illustration below.
How to Expand Rows and Columns |
Col 1 |
Col 2 |
Col 3 |
Row1 Col1 |
Row1 Col2
|
Row1 Col3
|
Row2 Col2 |
Row2 Col3 |
Row 3 Col1 |
Row 3 Col 2 |
Task 4: Add Table File-links to your Home Page
- Open your file index.htm.
- In the Table Pages section, add three paragraph elements.
- Link to one of the table files in each paragrah element, using the page title for the link text.
- Add the title=" " attribute to each, using the filename of the page.
- Save and preview, testing the links, and making any adjustments needed.
- Publish your new files, as well as your updated index file to your folder of the class Share file.
- Open the index file in the new location and test your links.
|