Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to wrap a long text in fixed length cell <td>

Posted on 2006-07-06
5
Medium Priority
?
1,680 Views
Last Modified: 2008-01-09
Hi

How to wrap the testrejttjjhji43252363253256236236263545454 text in <td width="20">?


Thank you
0
Comment
Question by:mmsreddy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 172 total points
ID: 17049805
You don't.

You can set <td width="20" style="overflow:hidden"> or use a serverside language to add spaces to the line yourself.

-r-
0
 
LVL 12

Assisted Solution

by:GoofyDawg
GoofyDawg earned 164 total points
ID: 17052104
Here's a Javascript function that will add hard line breaks to any string:

<script type="text/javascript">
  function addBreaks(str,len) {
    var result="";
    while (str.length > len) {
      result += str.substring(0,len) + "<br>";
      str = str.substring(len);
    }
    result += str;
    return result;
  }
</script>

You can replace the break with a space.

GoofyDawg
0
 
LVL 30

Assisted Solution

by:GrandSchtroumpf
GrandSchtroumpf earned 164 total points
ID: 17052359
javascript:(function() { var D = document; F(D.body); function F(n) { var u, r, c, x; if (n.nodeType == 3) { u = n.data.search(/\S{45}/); if (u >= 0) { r = n.splitText(u + 45); n.parentNode.insertBefore(D.createElement('wbr'), r); } } else if ((n.tagName != 'STYLE') && (n.tagName != 'SCRIPT')) { for (c = 0; x = n.childNodes[c]; ++c) { F(x); } } } D.body.innerHTML += ' '; })();

That's a nice "url" you can type in the address bar of the browser on any page you want (copy/pase is easier though, saving it as a bookmark is even easier).
It processes the complete document and adds <wbr> inside words that are longer than 45 chars.
You could call that method when your page loads, but it's rather slow to execute... it's better to only process the required elements.

And nobody said anything about the non-standard IE-only "wordwrap: break-word":  http://www.blooberry.com/indexdot/css/properties/text/wordwrap.htm
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question