?
Solved

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

Posted on 2006-07-06
5
Medium Priority
?
1,671 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
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…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

764 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