Solved

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

Posted on 2006-07-06
5
1,650 Views
Last Modified: 2008-01-09
Hi

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


Thank you
0
Comment
Question by:mmsreddy
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to create a tile layout 1 18
Problem to ToolkitScriptManager 2 30
CSS not updating in FF and ipad 6 41
HTML CSS 7 19
"I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
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 add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now