TABLES & TABLE FORMATS
|At one time or another everyone has seen a table presenting some kind of information. The material given is usually in a neat, concise, and readily understandable form. Creating or dealing with tables, especially when using HTML, is another matter. The stereotypical table can still be made, but HTML goes beyond this in the sense of viewing everything contained on a page, text and images, within the context of a table format. New things are happening and Table Formatting is being superceded by Cascading Style Sheets (CSS) to format HTML documents, as in HTML4.0 or the more recent XML. Nevertheless, tables and table formatting are still within the scope of HTML and can still be used to great advantage by WebTV users.|
In the descriptions that follow a usual table will first be represented. This is intended simply to introduce terms commonly associated with tables. Following this are some HTML table constructs and formats. Only the most basic can be given for a great number of variations are possible.
- Table Definitions -
- "Empty" Tables -
-1x1 Tables -
- 2x2 Tables -
- Color Attributes -
- Other Attributes -
- Table Formatting -
- Special Effects -
|Table Definitions Below is a representative table of 4 rows and 3 columns with all parts of it identified:|
|Rows, r, go horizontally across and columns, c, go vertically down the table. Each item within the table, (r,c), occupies a space, a "cell", the position for which can be specified by designating which row and which column the cell is located. For example, cell (3,2) refers to the position in the 3rd row and 2nd column.|
Having done all this numbering it will now be forgotten. HTML makes no use of numbering in creating tables. Rather, numbering is implied by the order in which rows and columns are constructed. For example, the HTML tags for a representative table of 1 row and 1 column is:
|‹tr›‹td› Content ‹/td›‹/tr›|
|Here the tag pair ‹table›, ‹/table› denotes where the table begins and ends. Between these tags are placed the rows the beginning and end for which are identified by the tag pair ‹tr›, ‹/tr›. On each row is a cell, the content for which is between the tag pair ‹td›, ‹/td›. The content of a cell may either be one word or character, as in the example, an image, or an entire paragraph or page of text, as is done in the writing of this document.|
|"Empty" Tables The introduction to tables is a learning experience, because even errors are instructive. Later, these become a device to help in "debugging", as when missing a less-than sign to an image statement for a cell content. Right now it is instructive to note that nothing but a table attribute, like "bgcolor" or "border" (see below), for the ‹table› tag has to be specified to have the basic set of table commands work. In other words, a completely "empty" table (no attributes) shows nothing when run. Put in one attribute and the table is not empty but gives a line, the thickness depending on what is chosen for a ‹table› tag attribute, e.g.,|
|Leave out the "bgcolor" attribute and just include the border attribute results in an embossed line:|
|A range of colored or embossed lines can thus be generated without having to resort to other means.|
|1x1 TablesTo more readily see the effect of creating a 1 x 1 table (one row, one column), an attribute will be introduced. This is the table attribute "border":|
|which has the effect of introducing a border around every cell in the table. A choice of either no border, # = 0, a thin border, # = 2, or a thicker border, # = 5, can be made, the higher the number the thicker the border. WebTV does not allow an attribute for a choice of border colors, but color can still be introduced in another way. Using the border attribute leads to:|
|The content of a cell is not restricted to text. It can also be an image, for example:|
|This particular image has a transparent background and has neither its width nor height given in the ‹img› statement. It should be noted how the border "hugs" the edges of the image in the cell, essentially creating a frame for it.|
|2x2 Tables Now, for two cells on a row each requires its own ‹td›, ‹/td› tags:|
|The HTML for the 2x2 table on the right is to its left.|
It must be noted that a browser "reads" from left-to-right and top-to-bottom. So the order in which a row is "read" is first cell first, second cell second, and so on. Similarly, the first row is "read" before the second, and so on. The position of a cell thus depends on where it is placed, and not on any numbering scheme.
A cell in HTML is not "just a little thing" into which a word or a number is placed. Each cell in HTML behaves as if it is its own page. Text and/or images can be fitted into each cell just as they would on a page. In fact, the example just given is no more than a 1x2 HTML table, the first cell containing the HTML codes for the table created in the second cell.
|Color AttributesA table in HTML is also not "just a table". It is a page in its own right containing smaller pages, which are the cells, these being separated by rows. To show this it is better to use color and width attributes both of which can apply to ‹table›, or ‹td› lead tags (note: the ‹tr› tag has no width attribute>,e.g.:|
|‹table width=? bgcolor=??›|
‹td width=? bgcolor=??›
|For example, using "yellow" in the color attribute for the 1x1 ‹table› lead tag of the previous image gives:|
|while for the text only 2x2 table above it gives:|
|Assigning just the second row of the 2x2 table a color, "ivory", for the attribute of its ‹tr› lead tag leads to: |
|And for this same table, the first cell of the first row may be given the color "cyan" as its ‹td› lead attribute:|
|Now the page-in-page nature of tables and cells become evident. The border attribute for a table outlines every independent cell. It will be noted that the "cyan" cell,like every other cells, is surrounded by a "yellow" border, since the table was given this color attribute. For the 1x1 image cell, this means the color of a frame depends on the color attribute chosen for the table. The ‹table bgcolor=?› attributes below are "yellow", "tan", and "black":|
|These colors will therefore determine the frame color. Using, for the cells ‹td bgcolor=?› attributes "black", "yellow", and "white" the images become framed by the colors chosen for the ‹table›:|
|Other Attributes Since the cells are "little pages" within a table, larger spacing between them should be thought possible. This would be like separating one table from another, only with cells instead. Doing this requires a cellspacing attribute, given in pixels, in the ‹table› tag:|
|It should be noted that cellspacing, and cellpadding , apply only to the ‹table› tag (e-mail comment: northeastdude). For the above 2x2 table a cellspace of 5 pixels has been assigned. The larger spacing between cells should be evident.|
Background space between a table border and the content of a cell can be altered with a cellpadding attribute, in pixels:
|In this instance a cellpadding of 10 pixels is assigned. The cell has expanded.|
Every cell in the 2x2 tables above has the same width, but this can be changed using the width attribute. A table has a width attribute as well, but its function is somewhat different. A reasonable working width for an entire screen is 520 pixels. To make a table of smaller width than the screen the ‹table› width attribute is used. This table is left-justified by default, unless a ‹center› tag precedes it.
Taking care with the mathematics, cells ‹td› can have their widths modified, the sum for the widths totalling to the width of the table, e.g.,
|In principle, since every cell has a width attribute, every cell in the 2x2 table should be able to be made a different width. In practice, it was not possible to do this, at least using a WebTV Classic. It is not known at present whether this will be possible using a WebTV Plus, or whether there are limitations to what can be done when assigning cell widths. The latter seems more likely. In the first 2x2 table only the second row had the cell widths varied, yet the first row was similarly changed; and in the second 2x2 table only the first row had the cell widths varied, and yet still the second row followed suit.|
Sometimes the format of a page may be viewed as having a row carry across two or more columns or, alternatively, as a column carrying across two rows. In such instances it is convenient, and less prone to error, to write a table format for these as if the missing columns or rows were actually there, but contained blank spaces. Then all the rows and columns could be said to be similar in size and could be sequentially numbered. Having thus identified which row or column is carried across an appropriate attribute, discussed below, would be applied to the cell. Whichever cells are lost in this process have their code erased, i.e., their ‹td›,‹/td› tags are eliminated together with whatever is in between.
For a 2x2 table in which a row spans two columns, the appropriate attribute is
and the resulting table becomes:
|For a 2x2 table where a column spans two rows the attribute is:|
and the resulting table is:
|Table FormattingTable formatting makes it a relatively simple matter to position text relative to an image. For example, using a 1x2 table format there is obtained:|
|It is appropriate to note here that the cell tag ‹td› has an align attribute which will position an image left, center or right. The above example has the align attribute center. An align attribute left (the default position) gives:|
|while the align attribute right gives:|
|When used with text in a cell it is best to restrict usage of the align attribute. With a single word or one-line phrase a ‹td› attribute of center will nicely put the text in the middle of the cell. With more lines of text this attribute will have every line centered. To gain a nice even left edge to the text it is best to use the default left attribute for ‹td›, as in the following example:|
|Text that is about the same height as the image will occupy a space of the same height and lines will wrap at the left margin of the image.|
|It is better to maintain the same height for text and image, so as not to have large voids above or below the image, unless a heading or a bottom caption is desired.|
| The above illustration demonstrates the vertical alignment,‹valign›, attributes for ‹td›. These are top, middle, and bottom. The horizontal alignment attribute center, ‹td align=center›, places the image at a center point in the cell.|
It is important to point out that judicious care must be taken when using textual content alongside an image. The height to the table will "grow" in proportion to the number of lines in a text cell in excess of the image height. It is best, using a trite phrase, "to keep things short and simple" to avoid this.
Two of the situations found to be difficult by many is to place text between images or to place an image between text. These can be done easily using a 1x3 table to create the format:
|In the examples that have been presented a border attribute has been used to show the dimensions of the resulting table. When coding using table formats doing the same at the onset provides a good guide for textual and image alignments. When these are satisfactory the border attributes can be either eliminated or set to zero so they will not show.|
|Special EffectsTo summarize, a sequence will be shown giving stages in a table formatting example. In the process two useful tips will be demonstrated, both based on using in image for a table background, i.e., the table tag is:|
‹table background=URL.gif (or.jpg"›
First it will be shown that text can be placed on an image, then an image will be superimposed on an image.
|Begin by creating a bordered table in which each cell is numbered and :|
|Introduce a word in appropriate cells to approximate the position of text or images. On a paper representation of this, lightly shade blocks of cells within which the text or images are to appear relative to one another. This will indicate the appropriate rowspan and/or colspan attributes to apply to the lead ‹td› tag of text or images and which numbered cells,‹td›##‹/td›,are to be deleted in gaining the desired format.|
Cells behave independently, so text in cells can be given differing colors using the appropriate ‹font› tags. Viewing the resulting bordered table provides an indication if the coding has been correct to this point; e.g.:
|9||Just apples in|
the light blue sea!!
|This shows how the colored text will appear when a background image is introduced as a table attribute.|
|9||Just apples in|
the light blue sea!!
|Finally, delete all numbers in cells and replace them by an HTML coded space,?=nbsp in & ? ; (no spaces between & and ;), this preserves cell integrity which otherwise would be lost with everything deleted. Replace the word used to indicate placement for an image with the URL for it. Finally, set the table border attribute to 0. This results in images being superimposed on an image, in this case with text on the image as well.|
| || |
| || |
| ||Just apples in|
the light blue sea!!
| || |
| || |
| || |
|Returning to the introductory example of placing differing colored frames about an image, these frames can now be made more ornate.Tables can be nested in tables.e.g.,|
|Varying the background color for each nested table creates a multicolor frame for an image:|
|Maintaining these same table background colors and varying the ‹td› background colors for cells outermost from the image introduces "striping" between the border frames:|
|Varying the width attribute in nested tables gives interesting effects as well (e-mail notes: ctpaso):|
|There is a WebTV only feature which applies solely to the ‹td› tag when making tables. These allow a gradual "rainbowing" type effect from the color chosen initially for the cell to some other color. The default is to take the initially chosen color given by "bgcolor" to some other color, "gradcolor", in the lead tag in a horizontal direction:|
‹td bgcolor=? gradcolor=?›
|The effect in going from red to yellow is shown here:|
|There is no restriction to shading in a horizontal direction. One has a full 360° to work with by use of the additional gradangle attribute:|
‹td bgcolor=? gradcolor=? gradangle=#›
#=number w/o symbol °
|The angle is taken from the horizontal direction going counter-clockwise, as shown here:|
|It is a matter of imagination to make use of this as well as the other table attributes available with WebTV.|
|Another WebTV only feature allows clickable cells:|
|This allows construction of, at least for, a personalized set of F-keys, e.g..|
|WebTV Resources||WebTV Utility|
|All other cell attributes are unaffected.|
The viewer has permission by this author to view or use the coding for all examples on this page, which has been written entirely using table formatting.
These are but a few of the formats possible using tables. The WebTV browser and/or the one limited to Classic users does not enable a demonstration of the total flexibility allowed in page formatting due to the small number of attributes enabled and which are available with other browsers. Nevertheless, considerable variation is within the available table attributes for WebTV and can be used to a users advantage.
Page writen and designed by: Art C.
Use with permission
Visit my home site
Like this page?
Send it to a friend!