Hands on your home page - Part 3

by Simon Grönlund

At the beginning of the time a web page was a flat text file sparsely formatted by HTML tags, as from the first hands on two numbers ago. But quickly pictures were added to these pages. And by the time any kind of bells and whistles have found their way into the web pages.

Still HTML is not at all suited for layout, not as well as modern desktop pagemakers are. But with force and a shoehorn web designers try to make flashy sites out of common HTML. This hands-on will give you a way to do the most basic layout to your site, and also point to some bad behaviours that you frequently suffer from.

Tables
In the early days of HTML tables were introduced, to be used as tables and no more. But in fact the tables had no restriction to what to stuff into them, as we soon will see. The area of this page that you are reading right now is in fact a table. And the three topmost links are stuffed into a small table that itself is located within a single cell of the bigger table, as you can see [here].

The HTML tag used to create a table is as simple as. To that we declare a new row with  and its partner  and at then we add cells with  and  each cell, TR is read TableRow and TD of course TableData. In some cases you would like headers each column and that is  and  on a row by itself (unfortunately my HomePage Publisher changes the code of this page so you can not view the source and see the code like I intended to). And a table caption is  and , inside the table tags but before the first row. Hence the table to the right is made of this code But we see no table and everything is packed together, it looks like we have to add something. Let us try to add a border, default is no border or BORDER=0, but now we add BORDER=2 within the TABLE tag. And further we add CELLPADDING=5 also within the TABLE tag. CELLPADDING tells the browser how many pixels to padd around the content inside the cells. CELLPADDING is very useful since you seldom want the text as packed together as seen in the previous example. There is CELLSPACING too, that gives the width of the lines between the cells, counted in pixels. I do not use that here, but please try it out yourself.

Now we will explore some more variables, like VALIGN and ALIGN. The default values are MIDDLE and LEFT respectively, but for vertical alignment TOP, MIDDLE and BOTTOM are valid, and horizontal alignment uses LEFT, CENTER and RIGHT.

If an entire row is to be vertical aligned the same way it is simplest to add VALIGN=?? to the row instead. These ALIGN and VALIGN can be used to both the table and the rows, test and see.

So far we have used equal number of cells each row, and no cell spans more than one row. But you may very well use COLSPAN or ROWSPAN to see to that. But I suggest you make a sketch of how you like to do the layout first, since it is very important you declare a new row when needed. Here comes a simple example and note how the cells are numbered. Here you easily understand that it is very easy get lost, and how will Netscape ever be able to figure out what you though.

It is this latter usage of ROWSPAN and COLSPAN together with a zero border that you may use to add layout to your pages. And do not forget that you may add another table within any cell you like. There is no end to what you may add to the cells.

Now I will mention the WIDTH attribute that may be added to both the TABLE and the TD tags. The WIDTH may be set in pixels or percent, but if pixels are used, do not forget that still many readers are using quite small screens, 640 x 480 is not that rare. Percent used on the table is computed from the browser's width or the available space within the cell it is located within, whichever is applicable. Shorthand, the percent of a table is computed from the available width.

But percent to the cells are counted from the table width. Hence a table may be set to a fix width i pixels, but the cell's width is computed in percent. Further it is possible to mix percent and pixel widths.

Still it is up to the browser to decide if the width you have set is to be used or not, but if everything else seems okay the browser most often is rather submissive, but do not trust it.

Also note the quotes. And note that each cell of the same column has to be of the same width, that is logical.

And a warning: Many word processors like StarOffice and others, loves to set the width without asking you. Many times it is better to let the width become the browsers choice, else anything may happen to the outcome.

Finally you may add colour to the table and/or the rows and/or the cells. The tag is BGCOLOR added within the TABLE, TR or TD tag. Here comes an example with mixed colours.

The preset colours available are as follows, but if there is need for more any value on the HEX standard is useful. That is for example. For a more detailed discussion, read the first article on HTML please. So far you will be able to do any layout you can think of. The most fancy site you visit uses some kind of table layout. It is only your imagination that sets your limit, or as said "the sky is the limit".

The pitfall
Many sites using tables start with a huge one splitting up the entire page in numerous smaller cell with both COLSPAN and ROWSPAN, or a few cells divided by new tables inside these cells. To that dozens of images and a lot of text is to be added. What is the result? A time consumer!

Since the browser can not begin to render nothing of a table until its content is known, that is the width and height of the images, the size of the texts etc. If there is only a few items it is no problem, but with numerous of them there is a lot of time gone before the browser can show you the slightest little character.

First, be very careful to tell the size of each image you use (read the former article). Second, try to use several tables only a few rows or only one row high, but put the tables on top of each other. This way the browser can start render your page much quicker and you must not wait until the entire page is downloaded. For example, this page uses one table at the top, then there is no table at all (except for the code examples used) until the bottom table. This way this page is rendered very quickly to you. But other pages uses one big table for the entire page, even if the most of it is text only, that perfectly well may be written without a table, or at least divided into a few tables piled up. Even better for text is to use the BLOCKQUOTE tag.

Another pitfall is that the very nice page you have made, that looks superb at your place, may look awful at other browsers. Still that is because it is always up to the browser to make the final decision on how to render a page. Thus, do not pay that many endless nights on that last pixel, it will never look that nice anyway.

A final word on tables. From time to time you must add that  token into an empty cell, that it will work the way you want. ( is no-break-space and can also be used whenever you want a white space but you do not like a line break at that space).

Thanks for this time. If you find a good looking site, do not hesitate to view the source of it and to use its ideas, the web is free.