GeoCities.us GeoCities.us » ResearchTriangle » Station Get your FREE home page!
TABLES FOR LAYOUT
2. Real Layouts: four skeletons that cover most home pages
LESSONS

1. The Basics

2. Real Layouts

3. When It Breaks

STUCK?
E-mail me

Look at enough home pages and you notice there are really only four or five shapes, dressed up differently. Here are the four I use. Each one has the code and a small working copy with the borders turned on, so you can see the skeleton. On your real page, set border="0" once it looks right.

A. The Sidebar
menu down the left, everything else on the right

<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
  <td width="25%" valign="top" bgcolor="#CCCC99">
    <a href="index.html">Home</a><br>
    <a href="photos.html">Photos</a><br>
    <a href="links.html">Links</a>
  </td>
  <td width="75%" valign="top">
    Everything else goes here.
  </td>
</tr>
</table>

WHAT YOU GET:

Home
Photos
Links
Everything else goes here. Notice the menu stays at the top even though this side is taller. That's the valign="top" doing its job.

Percent or pixels? A 25% menu gets skinny on a small monitor and wide on a big one. If your menu has pictures in it, give that cell a pixel width instead, like width="150", and leave the width off the other cell so it takes whatever is left. If the menu is only words, percent is fine. This site uses 20%.

B. The Newspaper
a banner on top, a sidebar, a footer across the bottom

Same as A, with a row on top and a row on the bottom that each stretch across both columns with colspan:

<table width="100%" border="0" cellpadding="8" cellspacing="0">
<tr>
  <td colspan="2" bgcolor="#003300">
    <font color="#FFFFFF" size="5">The Daily Me</font>
  </td>
</tr>
<tr>
  <td width="25%" valign="top">Menu</td>
  <td width="75%" valign="top">The news</td>
</tr>
<tr>
  <td colspan="2" align="center">E-mail and counter</td>
</tr>
</table>

WHAT YOU GET:

The Daily Me
Menu The news
E-mail and counter

That works fine. But this site is built a little differently: the banner, the middle and the footer are three separate tables, one after another. It looks the same, and the banner shows up on a slow modem while the rest is still arriving. More on why in When It Breaks, number 8.

C. The Centered Column
for pages that are mostly reading

On a big monitor, a paragraph that runs the whole width of the window is a foot long, and your eye loses its place going back to the start of each line. Put the whole page in one table and center it:

<center>
<table width="600" border="0" cellpadding="10" cellspacing="0">
<tr><td>
  Your whole page.
</td></tr>
</table>
</center>

Why 600? Plenty of people are still on 640x480 screens. A window that size, minus the scroll bar and the edges of the window, leaves you a little over 600 pixels before somebody has to scroll sideways, and nobody scrolls sideways. They leave. If you'd rather the column breathe a bit on bigger screens, width="85%" does nearly the same thing and never makes anyone scroll. Here's the percent version:

WHAT YOU GET:

Your whole page, in a column with gray margins on either side. On a wide screen the margins grow and the column stays easy to read.

D. The Thin-Line Box
my favorite trick, and every code box on this site

border="1" draws that raised, beveled, 3-D edge, which looks like every page from 1996. For a crisp one-pixel line instead, put a table inside a table:

<table border="0" cellpadding="1" cellspacing="0" bgcolor="#000000">
<tr><td>
  <table border="0" cellpadding="8" cellspacing="0" bgcolor="#FFFFFF">
  <tr><td>
    Anything you like.
  </td></tr>
  </table>
</td></tr>
</table>

WHAT YOU GET, AND THE OLD WAY BESIDE IT:

Thin line
border="1"

The outer table is black, with one pixel of padding. The inner table is white and sits on top of it, so exactly one pixel of black shows around the edge. Want a thicker line? cellpadding="2" on the outer table. Different color? Change the outer bgcolor. It looks the same in Netscape and in IE, which is more than I can say for almost anything else on this site.

Room between columns

Text in one column crowding up against the next? You can raise the cellpadding, or put an empty cell between the two as a gutter: <td width="15">&nbsp;</td>. Keep the &nbsp; in there. An empty cell does strange things in Netscape (page 3, number 3). Some people stretch a one-pixel see-through GIF in the gutter instead; that works too, and it's the only sure way to get a gutter narrower than a space.

On to 3. When It Breaks »

1. The Basics · 2. Real Layouts · 3. When It Breaks

[email protected]
Last updated: Saturday, September 18, 1999
© 1999 Anthony Perlman