CS403 Table Example 2

Basic Table 1
Ann 100 89 85
Stephanie 78 88 93
Brian 91 98 86
John 75 87 82
In this table we are representing four CS403 students and their grades on the quiz, first exam, and second exam. Notice that the table consists of 4 rows with 4 data cells in each row.
Basic Table 2
Ann 100 89 85
Stephanie 78 88 93
Brian 91 98 86
John 75 87 82
This is the same as the first table except that we have added cellpadding and cellspacing attributes to the <table> tag. In this example, cellpadding is adding 10 pixels of space around the contents of each cell; cellspacing increases the size of the dividers by 5 pixels.
Basic Table 3
Name Grades
Ann 100 89 85
Stephanie 78 88 93
Brian 91 98 86
John 75 87 82
Oops... Here we added an extra row to the top of the table to allow us to include heading information but this is not what we want it to look like! We used the <th> tag to indicate that the cells were going to contain heading information but we would like the Grades heading to span the three grade columns. Let's try it again...
Basic Table 4
Name Grades
Ann 100 89 85
Stephanie 78 88 93
Brian 91 98 86
John 75 87 82
Well that is better! Notice that we used the colspan attribute within the <th> tag and set it equal to 3 to indicate that we wanted this cell to span three columns.
Basic Table 5
Name Grades
Quiz Exam 1 Exam 2
Ann 100 89 85
Stephanie 78 88 93
Brian 91 98 86
John 75 87 82
Here we were trying to provide sub-headings for each of the three grades but this is not what we wanted it to look like...
Basic Table 6
Name Grades
Quiz Exam 1 Exam 2
Ann 100 89 85
Stephanie 78 88 93
Brian 91 98 86
John 75 87 82
Okay - that looks much better! All we needed to do was specify in the first row that the first cell needed to span 2 rows (that is, the cell that contained the word Name) so we added the rowspan attribute to it and set it equal to 2!

Some things to notice...

Valid XHTML 1.0! Valid CSS!