Fixed vs. Dynamic HTML Table Width

by Ankur Jain on November 3, 2008

There are two ways in which the table/cell width in HTML pages can be defined:

Fixed: Width is defined in pixels
Dynamic: Width is defined in terms of percentage of space available

Consider the tables below. They look alike but are coded differently. The first uses fixed widths, the second dynamic widths.

Fixed Width Col1 Fixed Width Col2
Text in the 1st column Text in the 2nd column
Dynamic Width Col1 Dynamic Width Col2
Text in the 1st column Text in the 2nd column

When to use Fixed, when Dynamic?

Use fixed widths if you require pixel-by-pixel control of the table layout (such as if you have embedded a background image and want to place text at a specific position).

A downside of fixed widths is inflexibility – the table may not render correctly on all browser resolutions.

Dynamic is the way to go, so that the table is displayed appropriately whatever the browser resolution may be, neither getting truncated if the resolution is too small nor leaving extra whitespace if too large.

Table Width Problem With Windows Live Writer

If you use Windows Live Writer for blogging, you will notice that it allows specifying table dimensions in pixels only. To work around this limitation, you can edit the source code to change its dimensions to percentages. Here’s how:

1. Define the table structure in Edit mode as usual.

2. Go the the Source view of the post. Locate the portion that defines the table. It will look as below.

3. Change the width values to percentages, as below.

4. That’s it! You’re done.

A word of caution: After changing to percentages, DO NOT tinker with the table/cell boundaries in the Edit view! If you do that, all your hard work will be lost – the dimensions will go back to their fixed pixel definitions. Put in percentages only after you are sure you will not change the table structure anymore in the Edit view.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: