HTML Table variability

In past columns, we have investigated the basic structure of HTML tables and their many properties; showing you how to create basic tables and insert data, images and additional code into them.

Many Web sites may require a deeper level of table imple­mentation. This month we investigate an advanced table technique, which enables you to set out your entire HTML page so it is sized equally on various screen size resolutions.

Screen sizes

The two most commonly implemented screen size resolutions are 800x600pixels (WxH) or 1024x768. Often you will encounter a Web site that requires you to scroll to the right to view the entire page content; this usually occurs if the developer has designed the site for the larger of these two resolutions, without considering how people using the smaller setting of 800x600 will see it.

You can find out which screen resolution your computer is set to, or change it for testing purposes. Right-click the desktop: a drop-down menu will appear from which you select Properties. Click the Settings tab and you'll see a sliding bar, which you can move to the desired resolution. Click Apply, then click OK to confirm.

Table variability

Table variability is the act of defining your table width so the Web page resizes itself according to the current screen resolution or browser window size used by the viewer.

Below is the code for a table with a width of 760pixels. This is how many people code their Web sites - setting a definitive width, which will NOT change if the screen settings change. If using this approach, for optimum display you should set the width to suit the smaller screen resolution and centre your table. The problem is that it will fill a comparatively small amount of a screen at 1024x768.

<table width="760" border="1" align="center">
  <tr>
    <td bgcolor="orange">One</td>
    <td bgcolor="pink">Two</td>
    <td bgcolor="yellow">Three</td>
  </tr>
</table>

This example sets out a basic one-row, three-column table with a width of 760pixels, centred on the screen. It fits quite snugly when the screen resolution is 800x600, but there is a lot of empty space on either side of the table at 1024x768.

Setting table widths

To allow for table variability, the first step is to set the table width to 100 per cent. If you were to insert "width=100%" in place of "width=760" in the above example, you would see that no matter what the screen resolution is, the table fills the screen.

TIP: You can do a simple test to check if your resizing works by clicking the Restore [Window] button (the middle button on the top right of your browser window, between the Minimize and Close buttons). Grab the corners of the window with your mouse and drag in and out to see the effect. Click it again to return to maximum resolution.

TD widths

Now that you know how to make your table adapt to various resolutions, you should look at specific cells (TDs). Using the above example, let's assume we want both the orange and yellow TDs to be 10 per cent of the page, regardless of size.

This would leave the middle cell to fill what is left over, which is 80 per cent of the browser window in this case. You can define this TD as well if you wish, but there is no need if the other cells are already set.

<table width="100%" border="1" align="center">
  <tr>
    <td bgcolor="orange" width="10%">One</td>
    <td bgcolor="pink">Two</td>
    <td bgcolor="yellow" width="10%">Three</td>
  </tr>
</table>

If you had decided to give your table a fixed width of 760, but still inserted the percentage widths in the TDs, then they would fill 10 per cent of the 760pixel-wide table. Essentially, you need to set the table width, so the cells can display that percentage.

Join the PC World newsletter!

Error: Please check your email address.

Struggling for Christmas presents this year? Check out our Christmas Gift Guide for some top tech suggestions and more.

Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Heidi Woof

PC World

Most Popular Reviews

Follow Us

Best Deals on GoodGearGuide

Shopping.com

Latest News Articles

Resources

GGG Evaluation Team

Kathy Cassidy

STYLISTIC Q702

First impression on unpacking the Q702 test unit was the solid feel and clean, minimalist styling.

Anthony Grifoni

STYLISTIC Q572

For work use, Microsoft Word and Excel programs pre-installed on the device are adequate for preparing short documents.

Steph Mundell

LIFEBOOK UH574

The Fujitsu LifeBook UH574 allowed for great mobility without being obnoxiously heavy or clunky. Its twelve hours of battery life did not disappoint.

Andrew Mitsi

STYLISTIC Q702

The screen was particularly good. It is bright and visible from most angles, however heat is an issue, particularly around the Windows button on the front, and on the back where the battery housing is located.

Simon Harriott

STYLISTIC Q702

My first impression after unboxing the Q702 is that it is a nice looking unit. Styling is somewhat minimalist but very effective. The tablet part, once detached, has a nice weight, and no buttons or switches are located in awkward or intrusive positions.

Latest Jobs

Shopping.com

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?