View Full Version : Stop table expanding with text

01-31-2005, 06:00 AM
I'm sure this has been asked many a time, but...

I have a table with various rows and columns. I want to put a new row using colspan for the number of columns in the table. The rest of the table just has a word or figure in each cell. Now I want to put a long text paragraph. Of course the text just expands the table to the width of the screen. Messy. Can I do something to make the table width dependent on all the rows EXCEPT this one? I.e, so the text wraps according to the existing width of the table?

Much obliged for any help!

01-31-2005, 07:01 AM
you could use the p tag and just use css to add a width to it that is no wider than the width of the table or in that td cell without using the p tag u can add nowrap to it and the text shouldn't expand the tabl
code for p tag with width defined by css

<p style="width:300px;">your paragraph text here</p>

01-31-2005, 07:33 AM
Sorry, I can't see the code you posted. I guess because I'm on an old Mac. Could you post it not between the tags?

Thanks a lot.

By the way, guessing at your coding here, I don't want to set a width for the table. The width is determined by the contents. It's a CMS not a web page.


01-31-2005, 07:49 AM
but if it is a table u can use the nowrap thing in a td cell
<td nowrap>your text here</td>
<td><p style="width:300px;">your paragraph text here</p></td>
one of those ways should work

01-31-2005, 09:56 AM
The nowrap causes it not to wrap, but I WANT it to wrap. But I want it to wrap at the width set by the rest of the table. Using the inline style requires me to stipulate a width for the paragraph. I don't want to declare a width - I want the table to decide.

In short, all the other contents can expand the table as necessary, but this paragraph should wrap within whatever width the rest of the table is. I don't know in advance what that width will be. It could be different every time as it will include data from a database.

01-31-2005, 10:19 AM
"My car won't start; can you tell me what's wrong? It's a blue one."

If you don't supply any detailed information it's nearly impossible to give conclusive answers; guesswork is all that remains.
Text consisting of words, separated by spaces should wrap; are there any non-breaking spaces (&nbsp) in there, perhaps?

01-31-2005, 11:50 AM
That's because I thought my question was of a general nature. Here's some code:

<table cellspacing="0" cellpadding="0" border="0" width="100%" height="85%"><tr><td align="center">

<table cellpadding="1" cellspacing="0" bgcolor="navy" border="0" bordercolor="black">
<tr align=center><font size="2"><td>&nbsp;From&nbsp;</td><td>&nbsp;Stu#&nbsp;</td><td background=bg.gif>&nbsp;</td><td>&nbsp;<b>TOTAL</b>&nbsp;</td><td background=bg.gif>&nbsp;</td><td>&nbsp;Fees&nbsp;</td><td>&nbsp;Materials&nbsp;</td><td>&nbsp;Advance&nbsp;</td><td>&nbsp;Other&nbsp;</td><td background=bg.gif>&nbsp;</td><td align="center">&nbsp;Source&nbsp;</td></font></tr>

<tr><td><?php echo $some_php_vraiables?></td><td>...and others.....</td></tr>

<tr><font size=2><td colspan="19" style='border-top:solid white 1px; padding:2px; color:orange;overflow=auto'>
<u>Note</u>: The above figures are for <?php echo $usemlong;?>. If you are is per the server time in the top right of the screen. Depending on where your server is, this could mean it is still the <i>previous</i> month - or has become the <i>next</i> month - at your server\'s location! The list above could therefore contain fees that were due last month, or omit fees that are due this month.<br>If this is the case you can either wait or, in any case, choose a different month:

<select name="whmth">
<option selected value="<?php echo $tmx;?>"><?php echo $tm;?></option>
<option value="<?php echo $lmx;?>"><?php echo $lm;?></option>
<option value="<?php echo $nmx;?>"><?php echo $nm;?></option>
and click:

<input type="submit" name="submit" value="Another month" class="button" />


Without the final <tr>...</tr> it stretches about two thirds across the width of the screen. This paragraph stretches it right across the screen. I want to keep it to the same two-thirds.

The general question is: in a table with a number of rows, how can I make one row wrap to the width of the table as it exists without that row - the width of the table being determined by its contents rather than a defined width in any tag??

01-31-2005, 01:05 PM
how can I make one row wrap to the width of the table as it exists without that row
To the best of my knowledge: you can't. The width of the table is related to the width of all of it's rows, where the widest determines the table width.
A table cell holding an amount of wrappable text will only shrink, forcing the text to wrap, if other reasons confine it's width. When no explicit width is set, and the contents of the various cells permit, a table will always shrink to fit the window width.

I did a little testing, and IE/win seemingly selects a width for each cell depending on the amount of content, so that each cell is filled up about equally, hight-wise.

I nagged you about being specific because general questions at best get general answers, which in my experience rarely help a lot.
Also, a lot of general questions stem from much more specific ones; knowing the details can often help in finding more suitable solutions.

01-31-2005, 01:29 PM
I had a feeling it couldn't be done. Shame, really, because it doesn't look so good. Either it goes right across the screen and leaves the contents of cells above looking lonely, or it's set to a width completely independent of the rest of the table...and looks just as ugly.

I nagged you about being specific because general questions at best get general answers, which in my experience rarely help a lot.
Also, a lot of general questions stem from much more specific ones; knowing the details can often help in finding more suitable solutions.

You're right, of course :thumbsup:


01-31-2005, 01:37 PM
I'm really still having a hard time constructing a picture in my mind, but you could try to set explicit widths for those cells that have fixed-width content so these cells don't spread out so much.
Another idea would be to set the table width to a silly minimum. That way, it will shrink-wrap all the cells' contents, and probably force your text to wrap, too.

01-31-2005, 03:40 PM
OK, here's what I did, and it seems to work.

In the cells above the text section in question there are only numbers or names or other data with only 2 words. No other long text entries, so this may not be posible in other situations.

Anyway, I set the width to a silly minimum, as you suggested. The names and 2-word entries had, of course, wrapped so I just put 'nowrap' in those td tags and it works a treat. I can do that easily because I'm getting the contents from a PHP loop.


Thanks for your help.

Oh, one last thing. Does 'nowrap' in the td tags work cross-browser, do you know?

01-31-2005, 04:27 PM
The nowrap attribute is part of the HTML 4.01 specification and should therefore be supported by compliant browsers -and I expect most of them do, but this attribute is deprecated.
Instead, CSS should really be used in the form of the white-space property: "white-space: nowrap;". You could use a class for those cells that need to not wrap (is that even proper english?) and control it through one simple rule.

01-31-2005, 04:40 PM
Thanks for the info and tip. CSS it is...