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">
    <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">
    <td bgcolor="orange" width="10%">One</td>
    <td bgcolor="pink">Two</td>
    <td bgcolor="yellow" width="10%">Three</td>

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.
Rocket to Success - Your 10 Tips for Smarter ERP System Selection
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Heidi Woof

PC World
Show Comments

Most Popular Reviews

Latest Articles


PCW Evaluation Team

Matthew Stivala

HP OfficeJet 250 Mobile Printer

The HP OfficeJet 250 Mobile Printer is a great device that fits perfectly into my fast paced and mobile lifestyle. My first impression of the printer itself was how incredibly compact and sleek the device was.

Armand Abogado

HP OfficeJet 250 Mobile Printer

Wireless printing from my iPhone was also a handy feature, the whole experience was quick and seamless with no setup requirements - accessed through the default iOS printing menu options.

Azadeh Williams

HP OfficeJet Pro 8730

A smarter way to print for busy small business owners, combining speedy printing with scanning and copying, making it easier to produce high quality documents and images at a touch of a button.

Andrew Grant

HP OfficeJet Pro 8730

I've had a multifunction printer in the office going on 10 years now. It was a neat bit of kit back in the day -- print, copy, scan, fax -- when printing over WiFi felt a bit like magic. It’s seen better days though and an upgrade’s well overdue. This HP OfficeJet Pro 8730 looks like it ticks all the same boxes: print, copy, scan, and fax. (Really? Does anyone fax anything any more? I guess it's good to know the facility’s there, just in case.) Printing over WiFi is more-or- less standard these days.

Ed Dawson

HP OfficeJet Pro 8730

As a freelance writer who is always on the go, I like my technology to be both efficient and effective so I can do my job well. The HP OfficeJet Pro 8730 Inkjet Printer ticks all the boxes in terms of form factor, performance and user interface.

Michael Hargreaves

Windows 10 for Business / Dell XPS 13

I’d happily recommend this touchscreen laptop and Windows 10 as a great way to get serious work done at a desk or on the road.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?