Forum Moderators: mack

Message Too Old, No Replies

can't get the table right

table unspecified column

         

kintantee

8:43 am on Sep 9, 2003 (gmt 0)

10+ Year Member



I'm trying to make a small table with 2 rows and 3 columns.

I want the first and third columns to be small columns and the second column, the middle column, to take up all the space in between. I do this by setting a specified table width, then specifing widths on columns 1 and 3, and then not specifing a width for the second (middle) column.

This seems to work, until I make the second row. It spans all 3 columns (colspan=3). When a few letters are written in this cell, the table stays fine, but when text (or an image) reaches the middle of the table, the cells in the first row get all out of whack. Why does it do this?

Thanks for reading, and hopefully helping... - Jesse

Oh, here's some code: (table looks fine unless the colspan=3 column has lots of text in it)

<html>
<body>

<table width=200 border=1 cellpadding=0 cellspacing=0 bordercolor=black>

<tr height=50>
<td width=50>&nbsp;</td>
<td>&nbsp;</td>
<td width=50> &nbsp;</td>
</tr>
<tr height=50>
<td colspan=3 align=center>&nbsp;</td>
</tr>
</table>

</body>
</html>

benihana

10:12 am on Sep 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you are fixing the table at 200, and the side cols at 50, why not specify the middle col as width=100. in the brief test i did this seemed to do the trick.

ben

mattglet

1:04 pm on Sep 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



or specify the bottom row with a width of 200

-Matt

kintantee

3:39 pm on Sep 9, 2003 (gmt 0)

10+ Year Member



well, the thing is, in the end, I want the middle column to stretch between the two fixed side columns. I want the table width set at 100% of window size. This is why I left the middle column width blank. But if I can't get this simple table to work, how am I supposed to get a more complicated one to work?! (I will eventually have like 5 columns)

mattglet

7:42 pm on Sep 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



wouldn't this work then?

<table width=100% border=1 cellpadding=0 cellspacing=0 bordercolor=black>

<tr height=50>
<td width=50>&nbsp;</td>
<td>&nbsp;</td>
<td width=50> &nbsp;</td>
</tr>
<tr height=50>
<td width=50>&nbsp;</td>
<td align=center>&nbsp;</td>
<td width=50>&nbsp;</td>
</tr>
</table>

-Matt

kintantee

8:33 pm on Sep 9, 2003 (gmt 0)

10+ Year Member



matt,
That doesn't exactly work. I want text and images to stretch across the entire window on the bottom row. This is why I had one cell and colspan=3. Things work fine, however, until I try to fill up the bottom row with text.

kintantee

11:53 pm on Sep 9, 2003 (gmt 0)

10+ Year Member



here's an interesting bit. This works:

<tr height=50>
<td width=50>&nbsp;</td>
<td>&nbsp;</td>
<td width=50> &nbsp;</td>
</tr>
<tr height=50>
<td colspan=3><img src="images/spda_title.gif" height=50 width=114></td>
</tr>
</table>

but changing the img width to 115 or anything higher makes row 1 go nuts! (nuts=bad) What's the deal?

kintantee

11:54 pm on Sep 9, 2003 (gmt 0)

10+ Year Member



oops, forgot... the first line is:
<table width=100% border=1 cellpadding=0 cellspacing=0 bordercolor=black>

davegerard

7:01 am on Sep 25, 2003 (gmt 0)

10+ Year Member



kintantee,
If your first and third columns are empty you can insert a transparent gif image (clear.gif) into the left and right cells and set the image width to 50 pixels and height to 1 pixel.

<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50"><img src="clear.gif" width="50" height="1"></td>
<td width="100%"></td>
<td width="50"><img src="clear.gif" width="50" height="1"></td>
</tr>
<tr>
<td width="100" colspan="3"></td>
</tr>
</table>

If you plan on having content in those columns you can either add another 3 column row that is 1 pixel in height and have the clear.gif image in the left and right columns

<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50" height="1"><img src="clear.gif" width="50" height="1"></td>
<td width="100%" height="1"></td>
<td width="50" height="1"><img src="clear.gif" width="50" height="1"></td>
</tr>
<tr>
<td width="50" valign="top"></td>
<td width="100%" valign="top"></td>
<td width="50" valign="top"></td>
</tr>
<tr>
<td width="100" colspan="3"></td>
</tr>
</table>

OR

You can nest a table of two rows in both the left and right columns and insert clear.gif into one of the rows of the nested table.

<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50" valign="top">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><img src="clear.gif" width="50" height="1"></td>
</tr>
<tr>
<td width="100%"></td>
</tr>
</table>
</td>
<td width="100%" valign="top"></td>
<td width="50" valign="top">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><img src="clear.gif" width="50" height="1"></td>
</tr>
<tr>
<td width="100%"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100" colspan="3"></td>
</tr>
</table>

ronin

12:15 am on Oct 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



kintantee>

The problem seems to be a rendering bug in IE.
I tried your code, which looks absolutely correct, in Mozilla Firebird and Opera. It worked perfectly in both. No matter what pixel-width I gave the image in the second row, the first and third columns in the first row retained a pixel-width of 50: only in IE did the column pixel-width (inexplicably) change.

If you give the image a pixel width of 100% though, the code works as it should in all three browsers.


<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="black">
<tr height="50">
<td width="50">&nbsp;</td>
<td>&nbsp;</td>
<td width="50">&nbsp;</td>
</tr>

<tr height="50">
<td colspan="3">
<img src="/myimage.gif" height="50" width="100%" border="0" alt="myimage">
</td>
</tr>
</table>

kintantee

5:40 am on Oct 17, 2003 (gmt 0)

10+ Year Member



Thanks for checking Ronin! I had nearly given up the design and almost went a different way on the page. I had no idea it was simply an IE bug. Now I know... - Jesse