chuckdawit
12-09-2007, 08:57 PM
Does anyone know how I can create <td> with some text that is the width of the text I put into it but not larger than a maxwidth?
I can set the width but then the <td> will always be that length and never any shorter. I want the <td> to be as short as the text but not longer than a defined width.
Can anyone help?
nap0leon
12-09-2007, 09:15 PM
What are you wanting to do with the extra text? Truncate it or wrap it?
What language does your site work in (ASP, PHP, C#)? (Or... what is your page extension (.php, .asp, .aspx)).
No matter which you are trying to do you will likely have issues with "maxwidth" being observed correctly for all inputs. An obvious approach is to count the number of letters that fit your "maxwidth" but since letters come in different widths, this would only be a guestimate of when to enforce "maxwidth" versus when to let the TD be not-so-wide.
Another approach might be...
1- let the TD contain all of the text with no constraints what-so-ever.
<td><div id="LimitThisToMaxWidth">Bunch of text, blah blah blah</div></td>
2- place a 1x1 pixel at the beginning of the text and at the end of the text.
<td>
<img id="LeftSide" src="empty.gif" height="1" width="1" border="0"/>
<div id="LimitThisToMaxWidth">Bunch of text, blah blah blah</div>
<img id="RightSide" src="empty.gif" height="1" width="1" border="0"/>
</td>
3- run some script that measures the distance between "LeftSide" and "RightSide" and if they are too far apart, update the width of the DIV to maxwidth.
I had something similar to the above working setting the height of DIVs, but I lost the sample and I don't have the time right now to recreate it. I'm sure Fang knows off the top of his head. =)