HTML, table question

LiamC

Storage Is My Life
Joined
Feb 7, 2002
Messages
2,016
Location
Canberra
Hi all, I need help. I sound like Tea now don't I? :eekers:

If you have a really long string of unbroken text that I need to display in a browser (HTML, in a table), is there a way to abolutely limit the table cell and force the browser to break and wrap the text, (to avoid horizontally scrolling) or do I have to write some script to break the text and let it wrap?

Cheers
 

Handruin

Administrator
Joined
Jan 13, 2002
Messages
13,916
Location
USA
I haven't found an exact solution just yet, but you could place the long string into a set of <textarea></textarea> tags.

There is a CSS attribute I found that works only for IE. "Word-Wrap:Break-Word"

Code:
<td STYLE="word-wrap:break-word;width:350;left:0">

If you have access to php, you can also try the wordwarp function. Not sure if it will cut a solid string, but if not there are ways to do it in PHP pretty easily.

Code:
<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "
");

echo "$newtext\n";
?>
 

blakerwry

Storage? I am Storage!
Joined
Oct 12, 2002
Messages
4,203
Location
Kansas City, USA
Website
justblake.com
wrapping should automatically occur at a space if you specify the table width... use the nowrap attribute to force non wrappage.


If it absolutely, positively needs to be wrapped then you have handy and his PHP or java script. Accept no substitutions or imitations.
 

Handruin

Administrator
Joined
Jan 13, 2002
Messages
13,916
Location
USA
Before I posted my last response, I tried adding the nowrap attribute to the <td> and <tr> tags (not at the same time) but it didn't stop a long string from expanding of the screen. I also specified a table width of 350 pixels to keep it from extending off the screen. As you said, if there is a space ni the string, it will wrap without the hacks I mentioned...that is essentially what the wordwrap and other varients do to make the string wrap.
 

blakerwry

Storage? I am Storage!
Joined
Oct 12, 2002
Messages
4,203
Location
Kansas City, USA
Website
justblake.com
the nowrap function specificly stops wrapping... in other words the point is not to wrap in order to preserve the structure of the text. It works best when placed in the <td> tag.


Yes, it's unfortunate that browsers require the space.. I wish there was a more absolute setting
 

Handruin

Administrator
Joined
Jan 13, 2002
Messages
13,916
Location
USA
There is for IE, as I mentioned above:

<td STYLE="word-wrap:break-word;width:350;left:0">

That option will wrap the longest of strings, but only under IE.
 

blakerwry

Storage? I am Storage!
Joined
Oct 12, 2002
Messages
4,203
Location
Kansas City, USA
Website
justblake.com
btw, I noticed moz isnt playing the catch up game with IE. Moz follows the standards and implements a few choice things on its own.

IE follows the standards and implements a few things on its own.

Neither party seems interested in supporting the other's proprietary changes. Which means we need better standards.
 
Top