Link to home
Start Free TrialLog in
Avatar of klidifia
klidifia

asked on

TD Widths with long woorrrrrrrrrrrrrrds

I have code like this to display messages from people

<table width=""120"" cellspacing=""0"" cellpadding=""0"">
<tr>
<td width=""120pxs"">

A reeeeealllllllllllllyyyyyyyyyyy long word will make it expand longer than 120 pixles

</td>
</tr>
</table>

What im trying to say if someone puts a really long word in a message that takes up more than 120 pixles wide then it will expand the <td>...

how do i stop this?
Avatar of dorward
dorward

Either:

(1) Check the data on the server to prevent insanly long words being included in the content.

(2) Change the design so it doesn't matter if long words are included.

(3) Take a look at the CSS overflow property. http://www.w3.org/TR/CSS2/visufx.html#overflow
I think your problem can be solved by adding this bit of CSS to your page:

<style>
<!--
.cell  {
  width=120
}
-->
</style>

then add this to whatever cell you don't want to expand:

<td class='cell'>

This should solve the problem
whoops, im a little tired.  That 'width=120' should be changed to 'width:120;'
nevermind... I tested it and it didn't work.  I would just use dorward's suggestions
My solution would be to add an error checking script to the form that the user uses to input the text. By using Javascript regular expressions it is possible to detect words over a given length, which you can then split with a space or hyphen.

The script should be similar to the following:

<script language="Javascript1.2">
     function checkData() {
          if (document.form1.textarea1.value.match(/\S{20,}/gi)) {
               alert ("Error: please hyphenate any words longer than 20 characters!");
          }
     }
</script>

the match(/.../gi) is a javascript function to match any characters within the slashes. The gi tells the script to check it globally and ignore case.

the \S matches any non-whitespace character, and the {20,} should cause the expression to match at least 20 times successively. You can change this to any length of word you want. After the comma, you can put in a max length, but that doesn't seem to fit what you need.
Easiest way to prevent cells resizing has always been images, and most common used are transparent ones a.k.a invisible table-in-correct-size-keepers :)

If it's possible, depending your site, you can make an image lets say xxx*y px which you put to another cell. Then your 120px cell will never resize and you don't have to use javascript,css or other tricks which might not work on older browsers.

An example where we have an table width of 500 px and we want to keep the left cell in 120 px.:

<table width="500">
<tr>
<td width="120">blablabla</td>
<td width="380"><img src="blank.gif" width="380" height="1">
</tr>
</table>

-EEK
ASKER CERTIFIED SOLUTION
Avatar of tipsypiglet
tipsypiglet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
EEK:

How will putting an image in a cell prevent the browser from widening the table when the content of another cell is too wide to render in the specified space?

tipsypiglet:

(a) The wrap attribute will not make the browser add wrap points to a word without any

(b) In HTML you can specify the width either as a number of pixel (width="123") or as a percentage (width="50%"), but you can't specify any other units [or pixels] so width="123px" is invalid. (In CSS on the other hand, units are required for all non-zero lengths).
Avatar of klidifia

ASKER

yeh i got some wrap thing and added it to css file, it worked
Just for the sake of knowing klidifia, what was the wrap thing?
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

<note>
Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>

If the user does not know how to close the question, the options are here:
https://www.experts-exchange.com/help/closing.jsp


Cd&

or ill just accept something as an answer? sheesh