Computers: writing a web page


Session 3 - images and tables

http://www.phototour.minneapolis.mn.us/classes/html3.html

Images

Images are inserted into web pages using the "<img>" tag. It requires a "src" attribute, which identifies the source of the image (a file, as a relative URL). There is no closing tag: <img src="pattern.jpg">

The image tag has several optional attributes. The src="___" attribute's value must be the filename of a .jpg or .gif file that's been uploaded to your server. The browser will display a broken-image icon if the file cannot be found (the spelling and capitalization must match exactly). Some of the more useful attributes are:

The code on the left created the graphics on the right:
<img src="Tbpattern_original.jpg" border=2 hspace=10 vspace=10
alt="Alternate Text" width=120 height=98>
desktop pattern
<img src="Tbpattern_original.jpg" border=0 hspace=0 vspace=0
alt="desktop pattern" width=90>
desktop pattern

Tip: avoid superfluous colors and images (intense primary colors and animated graphics on a resume, for example, would be a poor choice). Don't violate copyrights: make sure you have permission to use any photos or graphics you haven't created yourself (asking usually works for non-commercial use).

Hyperlinking images

Making an image hyperlinked is done by creating an opening anchor tag (a hyperlink tag), followed by an image tag, then immediately folled by the closing hyperlink tag:

<a href="pattern_original.jpg"><img src="Tbpattern_original.jpg"
border=2 hspace=10 vspace=10 align="right"></a>

Tables

The HTML tags for creating tables were designed for making rows and columns of data, like you might see in scientific papers. When the web became commercialized, they were used for page layout (that is, arranging graphics and text like you might see in a brochure or business webpage). When tables are used for page layout, the table border is usually invisible, so you don't know it's there.

Creating a table is the only way to have more than one column in a webpage design (such as a navigation bar on the left side of a webpage). Tables can be complex, with one table nested inside the cell of a larger tables, but only three tags are used (they all require a closing tag).

<table border=n cellpadding=n cellspacing=n
bgcolor="color" align="left/center/right" width="50%">

The table tag is used once for each table. It has several important attributes which control the alignment, size, borders, and spacing of the table.

Example:
<table bgcolor="cyan"
  border=2 cellpadding=10 width=200>
 <tr>
  <td>A Single-Cell Table</td>
 </tr>
</table>
A Single Cell-Table

<tr>

The table row tag is used once for each row in a table. All tables must have at least one row, and a closing </tr> tag must go at the end of the row: "<tr> (other tags) </tr>". The last row must be closed before the table is closed.

Example:
<table bgcolor="yellow">
 <tr>
  <td>Upper Left Cell</td>
  <td>Upper Right Cell</td>
 </tr>
 <tr>
  <td>Lower Left Cell</td>
  <td>Lower Right Cell</td>
 </tr>
</table>
Upper Left Cell Upper Right Cell
Lower Left Cell Lower right Cell

<td align="left/center/right" bgcolor="color" colspan=n rowspan=n>

This is for marking the beginning and ending of table cells (as above). All text and graphics in a table must go between an opening and closing table data(<td>) tag. This tag has attributes for alignment and background color, as well as some others unique to tables: "colspan=2" causes a table cell to bleed over 2 or more columns, and "rowspan=2" causes the same thing for rows. Example:
<table>
 <tr>
  <td bgcolor="white" align=left rowspan=2>Left Cell</td>
  <td>Upper Right Cell</td>
 </tr>
 <tr>
  <td>Lower Right Cell</td>
 </tr>
</table>
Left Cell Upper Right Cell
Lower right Cell

Other examples

These tags can be combined to create any kind of table configuration you want. One way to see how table tags can be used in complex ways is to find a page with a layout that appeals to you and study the source code. Below is an example that uses a giant upper-left cell:
<table bgcolor=yellow border=2 cellpadding=10>
 <tr>
  <td bgcolor="white" align=left
   rowspan=2 colspan=2>upper-left Cell</td>
  <td>Upper Right Cell</td>
 </tr>
 <tr>
  <td>center right cell</td>
 </tr>
 <tr>
  <td>Lower left Cell</td>
  <td>lower center Cell</td>
  <td>Lower right Cell</td>
 </table>
upper-left cell upper right cell
center right cell
lower left cell lower center cell lower right cell

Exercise

We will make your page at geocities match the one at: http://www.geocities.com/csgregerson/
Open this page first. Then go to "File" --> "New Window". In the second browser window, go to www.geocities.com and login to your account. Go to the "file manager", and click on the pencil icon to edit your page. You can use any text you like, but the page layout should match my page. Check your work by viewing the source code for my page ("View" --> "Source").
Contact: chris@phototour.minneapolis.mn.us