CLASS 4 : Positioning content on your Web page: HTML tables
REVIEW
The Rules Recapped
While experimenting with all the tags you've learned thus far, you must
remain mindful of The Rules of HTML and
the Anatomy of a Tag (covered in
Class 1). Until you're confident that you've commited to memory the
proper syntax for each of the tags covered in class, you should be sure
to refer to the guidelines provided in class, either on this course Web
site or from another trusty HTML authoring Web site (such as those
linked to from the "Further Reading" section). Some particular points
to remember include:
- Tags that require an opening and closing element work as a
container. In order to display the effect you intend, the
content you wish to modify must be contained within the
opening and closing elements of the tag.
Incorrect:
Click here!
<A HREF="http://www.w3c.org/"> </A>
Correct:
<A HREF="http://www.w3c.org/">
Click here!
</A>
- While tags can be used without attributes, attributes can never
be used without tags. That is, attributes can only be employed
within a tag and never alone.
Invalid:
<COLOR="#FF0000">
red text
</COLOR>
Valid:
<FONT COLOR="#FF0000">
red text
</FONT>
- Only attributes valid for a specific tag can be employed.
(Likewise, only values valid for a specific attribute can be
employed.) You cannot mix and match!
Invalid:
<FONT ALIGN="center">
center-aligned text
</FONT>
Valid:
<P ALIGN="center">
center-aligned text
</P>
- In order for your images to appear and for your links to work
properly, you must employ proper
UNIX Syntax. This includes
naming your files appropriately:
- All filenames should have appropriate and valid suffixes (i.e.,
.html, .jpg, .gif, .mov, .wav, etc.).
- All filenames should contain no spaces. To add visual spacing
in your filename, consider using the underscore ("_") character.
- Also, remember that, unlike HTML, UNIX is case sensitive
the file naming convention is to use all lowercase letters.
Unacceptable:
Web Page 1
Web Page 2.html
graphic1.psd
graphic2.eps
graphic fullsize.jpg
graphic thumbnail.jpg
Audio Clip
|
Acceptable:
webpage1.html
webpage2.html
graphic1.jpg
graphic2.gif
graphic_fullsize.jpg
graphic_thumbnail.jpg
audioclip.wav
|
TABLES
Tables are useful not only for presenting tabular data, such as those
found in spreadsheets, but are also primary technique HTML authors
currently employ to position content on a page.
<TABLE>...</TABLE>
Definition: The TABLE tag defines a table. Inside the TABLE
tag, use the TR tag to define rows in the table the TD tag to define
table cells (see below).
[display]
Attributes:
CELLPADDING="#"
Determines the amount of space, in pixels, between the border of
a cell and the contents of the cell. The default is 1. All cells
in a table will have the same padding.
CELLSPACING="#"
Determines the amount of space, in pixels, between individual
cells in a table. The default is 2. All cells in a table will
have the same spacing.
BORDER="#"
Indicates the thickness, in pixels, of the border to draw around
the table. Give the value as an integer. The default is 2.
WIDTH="#|%"
Defines the width of the table. The default is the optimal width
determined by the contents of each cell. The width value can be
a number of pixels, given as an integer, or a percentage of the
width of the page or parent element, given as an integer followed
by the percent sign. The table is scaled to fit the specified
height and width.
HEIGHT="#|%"
Specifies the height of the table. The default is the optimal
height determined by the contents of each cell. The height value
can be a number of pixels, given as an integer, or a percentage
of the height of the page or parent element, given as an integer
followed by the percent sign. The table is scaled to fit the
specified height and width.
BGCOLOR="color"
Sets the color of the background for the table. This color can
be overridden by a BGCOLOR tag in TD tags. Can use either name
or hexadecimal values.
ALIGN="left|center|right"
Specifies the horizontal placement of the table. LEFT aligns
the table on the left. The content following the table flows to
the right of the table. RIGHT aligns the table on the right.
The content following the table flows to the left of the table.
CENTER aligns the table in the center. Content does not flow on
either side. By default, a table starts on a new line and is
aligned with the following text
HSPACE="#"
Specifies the distance between the left and right edges of the
table and any surrounding content.
VSPACE="#"
Specifies the distance between the top and bottom edges of the
table and any surrounding content.
<TR>...</TR>
Definition: "Table row" specifies a table row. Use the
TR tag inside a TABLE tag (see above). The TR tag can contain TD
tags, which indicate table cells (see below).
<TD>...</TD>
Definition: "Table data" specifies a cell in a table.
Use the TD tag inside a TR tag inside a TABLE tag (see above).
[display]
Attributes:
ALIGN="left|center|right"
Specifies the horizontal placement of the contents of the table
cell. LEFT aligns the content with the cell's left edge. CENTER
centers the content within the cell. RIGHT aligns the content
with the cell's right edge. The default is left.
VALIGN="bottom|middle|top"
Specifies the vertical placement of the contents of the cell.
BOTTOM aligns the content with the cell's bottom. MIDDLE
centers the content within the cell. TOP aligns the content
with the cell's top. The default is middle.
WIDTH="#|%"
Specifies the suggested width of the table cell. The
WIDTH value can be a number of pixels, given as an integer, or
a percentage of the width of the table, given as an integer
followed by the percent sign. Depending on the actual width
of cell's contents, the cell may stretch to fit.
HEIGHT="#|%"
Specifies the suggested height of the table cell. The
HEIGHT value can be a number of pixels, given as an integer, or
a percentage of the height of the table, given as an integer
followed by the percent sign. Depending on the actual height of
cell's contents, the cell may stretch to fit.
BGCOLOR="color"
Sets the color of the background of the table cell. Can use
either name or hexadecimal values.
ROWSPAN="#"
Indicates the number of rows the cell spans. Give the value as
an integer.
COLSPAN="#"
Indicates the number of columns the cell spans. Give the number
as an integer.
NOWRAP
Specifies that the lines within a cell cannot be broken (that
is, they do not wrap onto the next line). Does not take a value.
Note:
If a cell is empty, that is, the <TD> tag is immediately
followed by the </TD> tag, the space occupied by the cell
in the table is completely empty. That is, the cell has no
content, no background color, and no border.
However, suppose you have a four column table, but you have no
data for the second column in one of the rows. You should still
provide the second TD tag for that row, because if you leave it
out the table will close the gap and move the third cell into
the second column. The row will end up having three columns only,
and it will not be aligned with the rest of the table.
If you want an empty cell to look like other cells in the table,
you can give it a period or a dash to indicate that the data is
unknown, for example, <TD>-</TD>.
USING TABLES FOR LAYOUT
Instead of thinking of tables as boxes within your HTML page (like
images), you can think of your entire page as a table
presenting your content in columns and/or rows, with different
background colors for different areas of content. HTML authors
do the real work of designing Web pages with their use of tables
there's an infinite number of ways of building a table to
present your content. You can (and should!) spend a great deal of
time tinkering with tables to figure out how to lay out your pages.
After you've got all the elements in your layout established, and
perhaps even marked up, it's a good idea to turn to paper and pencil
to block out your layout. Position your elements on the page in
relation to each other:
Menu
Link link link
Link link link
Link link link
Link link link
Link link link
Link link link
Link link link
|
Headline: Lorem ipsum dolor
|
Main content
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut
laoreet dolore magna aliquam erat volutpat. Ut wisi
enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea
commodo consequat.
Duis autem vel eum iriure dolor in hendrerit in
vulputate velit esse molestie consequat, vel illum
dolore eu feugiat nulla facilisis at vero eros et
accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait
nulla facilisi.
|
Secondary content
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut
laoreet dolore magna aliquam erat volutpat. Ut wisi
enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea
commodo consequat.
Duis autem vel eum iriure dolor in hendrerit in
vulputate velit esse molestie consequat, vel illum
dolore eu feugiat nulla facilisis at vero eros et
accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait
nulla facilisi.
|
|
|
Then, draw lines separating the elements into rows and columns:
Menu
Link link link
Link link link
Link link link
Link link link
Link link link
Link link link
Link link link
|
Headline: Lorem ipsum dolor
|
Main content
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut
laoreet dolore magna aliquam erat volutpat. Ut wisi
enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea
commodo consequat.
Duis autem vel eum iriure dolor in hendrerit in
vulputate velit esse molestie consequat, vel illum
dolore eu feugiat nulla facilisis at vero eros et
accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait
nulla facilisi.
|
Secondary content
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut
laoreet dolore magna aliquam erat volutpat. Ut wisi
enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea
commodo consequat.
Duis autem vel eum iriure dolor in hendrerit in
vulputate velit esse molestie consequat, vel illum
dolore eu feugiat nulla facilisis at vero eros et
accumsan et iusto odio dignissim qui blandit praesent
luptatum zzril delenit augue duis dolore te feugait
nulla facilisi.
|
|
|
Using this sketch as your guide, move from across from left to right and
down, carefully coding your table:
<TABLE>
<TR> <TD ROWSPAN="2"> Menu </TD> <TD COLSPAN="2"> Headline </TD> </TR>
<TR> <TD> Main content </TD> <TD> Secondary content </TD> </TR>
</TABLE>
Until you get the hang of working with tables, you might want
to consider coding your table all at once in one window and
create and markup your content in another window. Then, you can
carefully cut and paste your content into the appropriate
table cells.
After you've got this basic outline of your table coded, you
can then add cell padding and spacing, or a border, or background
colors, or, if you want to adjust the alignment in your table cells.
HTML STYLE
While technically, the way your HTML source code looks has no effect upon
the way your document will display in a browser, there are some common
conventions that make HTML easier to read. By indenting your table
rows and cells (using the Tab key), it's easier to scan down your
HTML source code and identify the structure of your table. One
style convention looks like this:
<TABLE>
<TR>
<TD ROWSPAN="2">
Menu
</TD>
<TD COLSPAN="2">
Headline
</TD>
</TR>
<TR>
<TD>
Main content
</TD>
<TD>
Secondary content
</TD>
</TR>
</TABLE>
Employing a standard style such as this one also makes it easier
to troubleshoot your code you can easily scan down your HTML
and notice irregularities. This is particularly important when
you're working with tables; you have to be very careful that you
follow The Rules of HTML very
carefully unclosed tags, improperly nested tags, and
invalid syntax can cause your content to display improperly, or
even to "disappear"!
SKILL MASTERY
Tables
- Set up a basic table and practice adding columns and rows,
changing the table width, and setting the border width, cell
spacing and cell padding.
- Practice setting the width and height of invidual table cells.
- Practice aligning content in individual table cells, both
horizontally and vertically.
- Set background colors in your table and in individual table
cells.
- Try setting some table cells to NOWRAP to see the effect.
- Try creating an "inline" table, by setting the alignment and the
horizontal and vertical spacing.
- Practice setting cells that span multiple columns and rows.
- Remove content from one table cell and see what the effect on
in the browser display is.
Planning your layout
- Identify the elements for each of your Web pages and decide how
how you want to position each element.
- Sketch out your layout on a piece of paper and draw in a table
layout around it.
- Code this table into HTML and add in your content.
HTML Style
- Go back and "clean up" the HTML you've already written, with an
eye to making your code easier to scan and read.
- Experiment with using tabs to indent your code until you come up
with a style that you're comfortable with and makes it easier
to scan and troubleshoot your code.
FURTHER READING
Tables
NEXT CLASS
Accepting input
HTML Forms
|