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 newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Heidi Woof

PC World
Show Comments

Father’s Day Gift Guide

Brand Post

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

Luke Hill

MSI GT75 TITAN

I need power and lots of it. As a Front End Web developer anything less just won’t cut it which is why the MSI GT75 is an outstanding laptop for me. It’s a sleek and futuristic looking, high quality, beast that has a touch of sci-fi flare about it.

Emily Tyson

MSI GE63 Raider

If you’re looking to invest in your next work horse laptop for work or home use, you can’t go wrong with the MSI GE63.

Laura Johnston

MSI GS65 Stealth Thin

If you can afford the price tag, it is well worth the money. It out performs any other laptop I have tried for gaming, and the transportable design and incredible display also make it ideal for work.

Andrew Teoh

Brother MFC-L9570CDW Multifunction Printer

Touch screen visibility and operation was great and easy to navigate. Each menu and sub-menu was in an understandable order and category

Louise Coady

Brother MFC-L9570CDW Multifunction Printer

The printer was convenient, produced clear and vibrant images and was very easy to use

Edwina Hargreaves

WD My Cloud Home

I would recommend this device for families and small businesses who want one safe place to store all their important digital content and a way to easily share it with friends, family, business partners, or customers.

Featured Content

Product Launch Showcase

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?