Improve Site Performance Increase Site Traffic Monitor Site Uptime Webmaster Resources NetMechanic Home Looking For Help? Partner Programs Privacy Policy Contact Us Press Room
NetMechanic Home LOGIN | HELP | ABOUT US | PRODUCTS | SITE MAP
NetMechanic Menu
Over 52 Million Web Pages Tested!     
 

Search for:


Your Email:

I would like to receive my newsletter in:
HTML format
Text format



Volume 8 (2005)
   September
   June
   April
   March
   January

Volume 7 (2004)
   November
   September
   July
   June
   May
   April
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 6 (2003)
   December
   November (Part 2)
   November
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 5 (2002)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 4 (2001)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 3 (2000)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June
   May
   April
   March
   February
   January

Volume 2 (1999)
   December
   November
   October
   September
   July
   June
   May
   April
   March
   February
   January

Volume 1 (1998)
   December
   November
   October
   September

 

HTML Tip:
Making a Wild Card Column Width

by Tom Dahm,
Chief Operations Officer,
NetMechanic, Inc.

  
March 2000
Vol. 3, No. 3
 • HTML Tip
 • CSS Tip
 • Promotion Tip
  

You can define a wild card column width for HTML frames, so why can't you do the same thing with your tables? You can, but it's not easy. You first have to delve into the idiosyncrasies of HTML tables.

Sometimes it's useful to build a table with a "wild card" column width. That is to say, you want a table where you set the width of most of your columns, but set the width of another column to take up the remaining screen area. To see what we mean, take a look at this page. When you re-size your browser window the left column stays at 100 pixels, while the right column changes to fit the screen width. This is a nice effect, but it's harder to achieve then you might think.

HTML allows you to define the width of a TABLE or TD tag in either pixels or percentages. However, unlike frames, you can't define a wild card width by using an asterisk.

To get around this, we might try experimenting with the WIDTH attribute for both the TABLE and the TD tags. For example, we try setting the overall width of your table to 100% of the screen width, while setting the width of our first column to 100 pixels, like this:

<TABLE BORDER="1" WIDTH="100%">
  <TR>
    <TD BGCOLOR="red" WIDTH="100">
      col 1, 100 pixels
    </TD>
    <TD BGCOLOR="green">
       col 2, wild card (I hope…)
    </TD>
  </TR>
</TABLE>

Under Microsoft Internet Explorer, this works exactly the way we want. Our left column stays at 100 pixels, and the right column takes up the balance of the screen.

Netscape Navigator, however, renders the table as shown below. Remember that Netscape doesn't like conflicting direction in your TABLE and TD tags. Since Netscape interprets column widths to be a *minimum * width, it resolves the conflict by stretching the left column to be wider than 100 pixels.

300 pixel width table under MSIE 5.0

Ok, since that didn't work, let's try something else. Let's set the width of our first column to be 100 pixels, then set the width our wild card column to "100%." We'll also drop the WIDTH attribute from the TABLE tag. This gives us the following code:

<TABLE BORDER="1">
  <TR>
    <TD BGCOLOR="red" WIDTH="100">
      col 1, 100 pixels
    </TD>
    <TD BGCOLOR=green WIDTH="100%">
      col 2, wild card (I hope…)
    </TD>
  </TR>
</TABLE>

You might think that this would make the browser allocate all of the remaining table width to the right column. Unfortunately, it doesn't. This tactic usually ends up squeezing the first column so that it's smaller than we want. In practice this approach causes the first column to be collapsed until its content refuses to be squeezed any further. The picture below shows our table as viewed under Netscape Navigator.

300 pixel width table under NN 4.02

So how can we solve this? The answer is to use the second approach, but to introduce a trick that keeps the browser from squeezing our first column. We can do this by putting a transparent GIF inside that column. We use a transparent, one-pixel graphic that we stretch to be the desired width of our column, like this:

<TABLE BORDER="1">
  <TR>
    <TD BGCOLOR="red" WIDTH="100">
      col 1, 100 pixels
      <BR>
      <IMG SRC="/images/Transhorz.gif"
         WIDTH="100" HEIGHT="1">
    </TD>
    <TD BGCOLOR="green" WIDTH="100%">
      col 2, wild card
    </TD>
  </TR>
</TABLE>

Now the browser tries to squeeze the left column as before, but the transparent GIF keeps the column from collapsing. As a result, we get the effect we want.

This approach works well in a variety of situations -- not just when you want a wild card column width. HTML coders often use spacer columns to separate content in a table. But browsers frequently squeeze empty spacer columns to the point where they disappear. Putting a transparent GIF inside these columns ensures that you'll get what you want.



Rate This Tip:
Not Useful Useful Very Useful   
 
NetMechanic Tools
HTML Toolbox
Browser Photo
Server Check
Search Engine Starter
Search Engine Tools
GIFBot
Newsletter
HTML Tutorial and Tips
Search Engine Tutorial
Accessibility Information
Browser Problem Tutorial

Company Info
Products
About Us
Contact
Advertise
Link To Us
Jobs
Privacy Policy
Partner Programs
Press Room
RSS Feed
Support
 



Powered by Overture!

 
     
 
   
 
     


Keynote Home
Copyright © 1996-2007,
Keynote NetMechanic
All rights reserved.