Solved

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

Posted on 2006-07-06
5
1,665 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 43 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 41 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 41 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

687 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