Maddog's HTML for Real People Chapter 10, Lesson 4


[INDEX] Ch 10, L 4 - Specifying Cell Size

If you already know how to explicitly size a table's cell, you can skip this lesson.

Sometimes, the Web page author wants to assure that a table looks pretty much exactly as expected, and not rely on the browsers algorithm (formula for calculating) to determine the size of the table and it's cells. Other times, in order to make sure the table aligns with a background (image) feature, it's important that a column or row of cells be a particular size.

HTML allows this level of control, for individual cells, by virtue of the 'HEIGHT' and 'WIDTH' attributes. Lest you confuse these with attributes for the <TABLE> tag (which are nevertheless similar), these attributes are specified in the individual cell tags, i.e., the <TD> tag and/or the <TH> tag.

For specifying the cell width, then, in screen pixels, we have:

<TD WIDTH=number-of-pixels> (for data cell)
or
<TH WIDTH=number-of-pixels> (for heading cell)

For specifying the cell height, in screen pixels, use:

<TD HEIGHT=number-of-pixels> (for data cell)
or
<TH HEIGHT=number-of-pixels> (for heading cell)

Naturally, its quite common to specify both attributes (applicable to <TD> or <TH> :

<TD HEIGHT=number-of-pixels WIDTH="number-of-pixels">

Be aware that these attributes, when specified by the HTML author, may be superceded by the browser's built-in rules. In the case of a conflict between specifications for cells in the same column or row, for example, the browser will decide how to build the table based on its own best compromise.

Let's look at some examples:

HTML Source Code Follows:

Here's a table with default cell dimensions:
<P>
<TABLE BORDER=5>
<CAPTION>Demo Table 1 </CAPTION>
<TR ALIGN="CENTER"><TH>NoSpec</TH><TH>NoSpec</TH></TR>
<TR ALIGN="CENTER"><TD>NoSpec</TD><TD>NoSpec</TD></TR>
<TR ALIGN="CENTER"><TD>NoSpec</TD><TD>NoSpec</TD></TR>
</TABLE>
<P>
Here's a table with the first column's heading and data specified in screen pixels:
<P>
<TABLE BORDER=5>
<CAPTION>Demo Table 2 </CAPTION>
<TR ALIGN="CENTER"><TH WIDTH=150 HEIGHT=75>W=150 H=75</TH>
    <TH>NoSpec</TH></TR>
<TR ALIGN="CENTER"><TD  WIDTH=100 HEIGHT=35>W=100 H=35</TD>
    <TD>NoSpec</TD></TR>
<TR ALIGN="CENTER"><TD  WIDTH=100 HEIGHT=5>W=100 H=5</TD><TD>NoSpec</TD></TR>
</TABLE>
<P>
Here's a table with minimum number of attributes to fully specify the entire table:
<P>
<TABLE BORDER=5>
<CAPTION>Demo Table 3 </CAPTION>
<TR ALIGN="CENTER"><TH WIDTH=150 HEIGHT=75>W=150 H=75</TH>
    <TH WIDTH=100>W=100</TH>
    <TH WIDTH=100>W=100</TH></TR>
<TR ALIGN="CENTER"><TD HEIGHT=25>H=25</TD>
    <TD>NoSpec</TD>
    <TD>NoSpec</TD></TR>
<TR ALIGN="CENTER"><TD HEIGHT=35>H=35</TD>
    <TD>NoSpec</TD>
    <TD>NoSpec</TD></TR>
</TABLE>
(End of HTML Source Code)

Demonstration Follows:

Here's a table with default cell dimensions:

Demo Table 1
NoSpecNoSpec
NoSpecNoSpec
NoSpecNoSpec

Here's a table with the first column's heading and data specified in screen pixels:

Demo Table 2
W=150 H=75 NoSpec
W=100 H=35 NoSpec
W=100 H=5NoSpec

Here's a table with minimum number of attributes to fully specify the entire table:

Demo Table 3
W=150 H=75 W=100 W=100
H=25 NoSpec NoSpec
H=35 NoSpec NoSpec

(Demonstration Ends)

There's a lot of stuff to go over here:

Specifying cell dimensions can be a lot of trouble, and makes the table considerably more complicated to author using a text editor, not to mention less readable in source code. Still, it can allow you to do some pretty dazzling things with your web page, which we'll demonstrate in a future chapter. Before we can address those fancy applications, however, we have to thoroughly understand the basic workings of table tags and their attributes.


-PREVIOUS- -CHAPTER- -INDEX- -NEXT-

Overseer: Monty Northrup ... maddog@io.com ... leave e-mail ...
...to maddog 'n' miracles homepage...