XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The...

35
XHTML Tables

Transcript of XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The...

Page 1: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

XHTML

Tables

Page 2: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Tables Tables create little boxes in which

you can place things to keep them organized.

The little boxes are called table cells.

Tables are created using the <table> tag.

Open your template.htm file and create the following table with me.

Page 3: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Creating a Table

<table><caption>My First Table</caption><tr>

<th>Name</th><th>Class</th>

</tr>(cont’d)

Designates a new row in the table

Designates headings

Designates the end this row

Designates start of table

Page 4: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Creating a Table

<tr><td>Sue</td><td>sophomore</td>

</tr><tr>

<td>Joe</td><td>junior</td>

</tr>

Designates a table data cell

Page 5: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Creating a Table

<tr><td>Sally</td><td>senior</td>

</tr></table>

Specifies the end of this table

Page 6: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Table Cells <td></td> table data. This element

creates individual cells in a row. Content of a table goes in this element.

<th></th> table heading. This element is like the <td>, but also displays the text inside the cells as centered and boldface

Page 7: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Table Tag Attributes The table tag can have attributes

that specify additional formatting for the entire table.

Syntax:<table border=“size” >Try different size borders on your

table – try 1, 5, and 10. Tip: Set border="0" to display tables

with no borders!

Page 8: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

cellspacing Attribute Cell spacing controls the amount of

space inserted between table cells.Syntax:<table cellspacing=“size”>Default size is 2 pixels.Experiment with cellspacing. (Don’t

delete the border attribute) Try values such as 0, 1, 5, and 10 pixels.

Page 9: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

cellpadding Attribute Cell padding controls the space

between the table text and cell borders.

Syntax:<table cellpadding=“size”>Default size is 2 pixels.Experiment with cellpadding. Try

values such as 0, 1, 5, and 10 pixels.

Page 10: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

cellpadding vs. cellspacing

Cell Contents

Cell Contents

Cell Contents

Cell Contents

cell spacing is between the border of each cell (blue)

cell padding is between a cell’s contents and its border (orange)Table borderCell border

Page 11: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Table width Attribute The syntax for specifying table size is:<table width=“size”>Size is the width of the table, either in

pixels or as a percentage of the display area.

Example<table width=“75%”><table width=“400”>

Page 12: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Caption Element A table caption is used to tell the

reader what the table is for. The <caption></caption> element is

placed immediately after the <table> tag.

Example<table><caption>Figure 1 – 2004 Profit</caption><tr>

Page 13: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Cell Alignment Attributes You can align individual cells in order

to make your table more readable. Defaults

Headings <th> - centered, vertically and horizontally

Cells <tr> and <td> - centered vertically, left-aligned horizontally

Page 14: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Cell align Attributes To change the default horizontal

alignment of a cell use the align=“alignment” attribute with the <th>, <tr> or <td> tags.

Where alignment is either “left”, “right” or “center”.

Page 15: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Cell valign Attributes Another attribute,

valign=“alignment” allows you to control vertical alignment of cells.

Valid values for alignment are “top”, “middle”, and “bottom”.

Page 16: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

align and valign values

Page 17: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Table colors

You can also use style sheets to control table colors

You can change colors for the entire table, or for a given row, or even a single cell using CSS.

Page 18: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Table colors Use an internal (embedded) style

to change all tables Example:

<style type=“text/css”>

table {background-color:blue;color: white; }

th {background-color:gold;color: navy; }

caption {color: navy; }

</style>

(cellspacing=“0”)

Page 19: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Table colors Use an inline style (the style

attribute) to change one particular cell.

Example:<td style="background-color:#FFCC99;

color:navy">Cell 4</td>

Page 20: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Empty Cell A <td>element

that has no content will not display correctly

Use &nbsp; as the content

Page 21: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Table Summary <table> </table> - the start and end of

a table <tr> </tr> - the start and end of a row in

the table <th> </th> - a heading box on the table <td> </td> - a data cell in a table row <caption></caption> - a description

for your table

Page 22: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Attributes for <table> <th><td><tr>

border cellpadding cellspacing width

align valign

Page 23: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Assignment #1

Create a calendar page for the month you were born – use caption for the month.

Use styles for color. Add some text Add an image on your birthday To align the days to the top of the calendar,

use <tr valign=“top”>. To keep a border on a blank cell, use &nbsp;

for the text. (no breaking space)

Page 24: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Spanning Rows & Columns A basic table contains cells of data

arranged in columns and rows. Sometimes the contents of a cell

apply to more than one row or column.

You can mark a single cell to be part of multiple rows or columns – known as spanning.

Page 25: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Spanning Rows & Columns Spanning is done by using the

rowspan or colspan attributes in the <td> or <th> tags.

Examples<td colspan=“2”><td rowspan=“3”>

The number indicates the number of rows or columns to span

Page 26: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

rowspan

<tr> <td rowspan=“2”>Span</td> <td>1</td>

<td>2</td></tr><tr><td>3</td>

<td>4</td> </tr>

1 2

3 4Span

Page 27: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

colspan

<tr> <td colspan=“2”>Span</td> <td>1</td> </tr><tr><td>2</td>

<td>3</td><td>4

</tr>

1

2 3 4

Span

Page 28: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Spanning Rows & Columns<table border="1"><tr>

<td colspan="2">&nbsp;</td><td rowspan="2">&nbsp;</td>

</tr><tr>

<td>&nbsp;</td><td>&nbsp;</td>

</tr></table>

 

 

   

Page 29: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Let’s create the following:

Page 30: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Set up the table:

<title>Spanning columns and rows</title></head>

<body><table border="5" cellspacing="0“ cellpadding="4"><caption>Race Results</caption>

</table>

Page 31: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

First row

Runner needs to span 2 cols<tr> <th colspan="2">Runner</th> <th>Time</th> <th>Origin</th></tr>

Page 32: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Second row Men spans 3 rows<tr> <th rowspan="3">Men</th> <td>1. Peter Teagan </td> <td>2:12:34 </td> <td>San Antonio, Texas </td></tr>

Page 33: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Rows 2 and 3

<tr> <td>2. Kyle Wills </td> <td>2:13:05 </td> <td>Billings, Montana </td></tr><tr> <td>3. Jason Wu</td> <td>2:14:28 </td> <td>Cutler, Colorado </td></tr>

Page 34: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Complete the table

Page 35: XHTML Tables. Tables create little boxes in which you can place things to keep them organized. The little boxes are called table cells. Tables are created.

Assignment #2

Reproduce a TV programming schedule for one week.