Basic Tables and Page Layout
Steve Benninghoff
Dept. of English Language and Literature
Eastern Michigan University
steve.benninghoff@emich.edu


What this Lesson Covers:
  Tables as Page Layout
  Basic Table, Tags, and Structure
Attributes:
  Color
  Width & Height
  Cellpadding & spacing
  Colspan & Rowspan
Common Uses
  Schedule Pages
  Face or Portfolio Pages
   
   
   
   

 






Tables: The Tool for Page Layout

Tables are the main method of page layout in basic html. The idea is fairly strightforward - you can create a grid to mark off sections of your page into rows and columns. Then you can do various things to either make the table more or less visible according to your needs.

Most often when you see the common page layout that looks like this, you're likely seeing a table of 2 columns and 3 rows, with the top row of cells merged, and the left-hand or scan column merged vertically as well.
1A + 1B - Page Head
2A
+
3A
2B - The body material of the page generally goes in here. yada yada yada yada yada yada yada yada yada yada yada yada
3B

Here is another example from one of my own course home pages:

Here as well, the basic grid of the page and arrangement of the text is created using tables, though here the borders are off and no colors are used so the table itself is invisible.


The Basic Table

Tables are created by three basic kinds of paired tags, the table tag, the table row tag, and the table data tag. They are arranged in nested fashion, with the table tag "containing" the table row tags, and the table row tags containing the table data tags "inside" them.

Here's the simplest table you can have - with a single row, and a single cell inside that row, with the border set to 1 so we can see it.

<table border="1">
   <tr>
      <td>
      </td>
   </tr>
</table>
Here is some text to fill up this space and make sure the table expands to several lines of text.

When you first work with tables, it is a good idea to set the border attribute to 1 ( as above) so you can see the structure you're setting up. Later you can change this to "0" and your grid becomes invisible. Here is a more complex table, with three rows and three columns, so you can see the nested structure of the tags - cells inside rows inside table.

<table border="1">
   <tr>
      <td>A1</td>
      <td>B1</td>
      <td>C1</td>
   </tr>
   <tr>
      <td>A2</td>
      <td>B2</td>
      <td>C2</td>
   </tr>
   <tr>
      <td>A3</td>
      <td>B3</td>
      <td>C3</td>
   </tr>
</table>
A1 B1 C1
A2 B2 C2
A3 B3 C2

As you can see, once you have multiple rows and columns, the tags formatting the table can get quite extensive. This will be especially true when you begin nesting tables inside of tables (see below). For this reason WYSIWYG web page editors can be very helpful once you start dealing with complex pages. But knowing and understanding the basic structure and rules is the only way to troubleshoot pages when the fancy editors don't give desire results. These issues will be covered in more depth by following presenters.

Color
(bgcolor="#CCCCCC")
So once you have the basic idea of laying out a table as such, the attributes and features of tables become important. For example you can set the background color and text color for table parts separately. You can set them for an individual cell, for an individual row, and table-wide as well. The most local setting holds, so the setting for a cell should overide the setting for the entire table.

Width and Height (width="90%" height=120)
You can also set the width and height of the table, and individual cells (not rows). So if you want to make sure your table maintains various proportions, or fix the size of parts, you can do so. There are two main ways to set widths and heights, with fixed "pixel" widths (a pixel is a single dot on your computer screen) or with a percentage of available space. If you set the width of your whole table to be 90%, it will fill up that much of the available space. If you then set the first cell to be 90% in width, it will take 90% of your table's width, as below:

A1 B1

That table looks like this:

<table border="1" width="90%">
   <tr>
      <td width="90%">A1</td>
      <td >B1</td>
   </tr>
</table>

Note that if you set the width of the whole table with percentages, and the table is not inside another one of fixed width (see nesting tables below), it will scale to the width of the screen, which can give the reader an impossibly long line of text to read and work with. For reasons like this, and because designers want to maintain the look they designed, fixed pixel widths are often used for tables and cells as well. Like this:

A1 B1 C1
A2 B2 C2

That table looks like this:

<table border="1" width="300">
   <tr>
      <td width="50">A1</td>
      <td width="200">B1</td>
      <td width="50">C1</td>
   </tr>
   <tr>
      <td>A1</td>
      <td>B1</td>
      <td>C1</td>
   </tr>
</table>

Notice that setting the width for the top cell in a column will set it for those below. Also notice that the width of the rows needs to total to the width of the table, if one has been specified. A last note on widths and heights is that table cells will expand if their contents are larger than the set limits.

Colspan & Rowspan
It is also possible to combine cells in a table to create larger, non-uniform spaces, with the colspan and rowspan attributes. These are applied to individual table cells. Thus:

<table border="1">
   <tr>
      <td colspan="3">
       A1
      </td>
   </tr>
   <tr>
      <td rowspan="2">
      A2 + A3
      </td>
      <td>B2</td>
      <td>C2</td>
   </tr>
   <tr>
      <td>B3</td>
      <td>C3</td>
   </tr>
</table>
A1 + B1 + C1
A2
+
A3
B2 C2
B3 C2


Cellpadding and Spacing
The last features of tables I'll cover here is the spacing inside of a cell, called cellpadding (like an interior "margin") and the space between cells, not surprisingly called cellspacing. These are both attributes you set for the entire table, so they go inside the table tag, like so:
    <table cellpadding="8" cellspacing="4">

Here is an example table using color to illustrate this set of features:

Here is our Header Row
This is our scan column.      
     
     

Notice the cellpadding, or interior margin on the cell, and the cellspacing, the blue inbetween cells. This is created by giving the entire table a blue background color, border set to zero, but spacing set to four, and then giving the cells their own individual colors.

Nesting Tables
A last notes about using tables is that for many purposes you will actually want to use tables inside of tables. For example the "bottom layer" structure of the page you are reading is set up with one rather large table. But then each individual presentation you are being shown, of table and code side-by-side, consists of a table inside the larger table. Again for larger and more complex pages like this, it will be advantageous to use a visual editor, but one needs to understand the code to tweak and fix problems in the page construction, but more will offered on that later. Here is a nested table I sometimes use to show argument structure to students:

Your Paper
Introduction
Body
Body Sections
Claim
Support
Warrant
Claim
Support
Warrant
Claim
Support
Warrant

Conclusion



Three More Common Uses of Tables
Finally here are two further examples of uses of tables beyond the course home page - the schedule page and face or portfolio pages.

Schedule Pages
Here are two approaches to schedule page set ups:

Using colors:

Date In-Class Homework
Day 1 Discuss Orwell's "Politics and the English Language" Write a one-page application of Orwell's ideas to your experience
Day 2 Paper Workshop Bring Drafts
Day 3 Discuss paper feedback Revise papers

The opposite approach - the invisible table:

Week 1  
  Day 1 Discuss Orwell's "Politics and the English Language" Write a one-page application of Orwell's ideas to your experience
  Day 2 Paper Workshop Bring Drafts
  Day 3 Discuss paper feedback Revise papers

Face Pages, Portfolio Pages, and the like
Sometimes you will want to have students construct online portfolios of their work, or you may want to work to construct more community in your classroom (many of my students this semester still don't know each other's names). You can use tables to help set up face pages or portfolio page structures:

Hobbes' Porfolio
Paper 1
Paper 2
Paper 3
Paper 4

Face Page for Cartoon Composition

Hobbes

Stan


Cartman


Gromit

Barbrady

Wendy

Cow

Wallace


Syllabus and Policy Pages

Finally tables work well for setting up syllabus and policy pages, where the heading for a given section can be set out in a scan column to the left, either with returns to create spacing or an empty table row as a spacer.

Required Texts Web Style Guide: Basic Principles for Creating Web Sites. by Patrick Lynch and Sarah Horton. Yale UP, 1999. Companion Web Site at http://info.med.yale.edu/caim/manuel
  The Non-Designer's Web Book, 2nd Ed. by Robin Williams and John Tollett. Peachpit Press, 2000.
   
Attendance As this is a workshop class, we will be doing a great deal of active writing work in class. If you are not here, you cannot get the benefit that the course offers. So aside from university regulations, attendance is required for this course. You will be allowed two free absences - no questions asked - after which each additional absence will effect your final grade.
   

In this example the headings are bolded and the alignment attribute for their table cells is set to right aligned (<td align="right">) so that they are close to the text they refer to.


A Cheat Sheet of Tags, Terms


The Basic Tags:
<table>
   <tr>
      <td>
      </td>
   </tr>
</table>

Main Attributes:
attributes modify the object created by the tag - so the attributes of a table modify the whole table, while those of a row, just that row, and the cell just that cell.
table: border="1", cellpadding="2", cellspacing="3", width="50", height="50", align="left-right-center", valign="top-middle-bottom", bgcolor="#CCCCCC", background="bckgnd.jpg"
 
tr: bgcolor, background
 
td: width="50", height="50", align="left-right-center", valign="top-middle-bottom", bgcolor="#CCCCCC", background="bckgnd.jpg"