Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unordered lists (HTML ul tags) are very handy to create menus of all types, shapes and sizes.  All it takes is a little knowledge of CSS and the possibilities are endless. First off, you should know the general format for menus created using the …
CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
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…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

864 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

20 Experts available now in Live!

Get 1:1 Help Now