PHP Developers Network
http://forums.devnetwork.net/

td word wrap in all browsers
http://forums.devnetwork.net/viewtopic.php?f=68&t=140400
Page 1 of 1

Author:  cjkeane [ Sun Oct 12, 2014 6:24 pm ]
Post subject:  td word wrap in all browsers

Hi everyone:
I've searched the net for quite a while but haven't found a solution to my issue so I thought I'd post my coding here to see if anyone could recommend a solution.

I need text to wrap within a cell, but I've found that some text goes outside the line and does not wrap. Any help would be appreciated. Thanks.

the css I use is:
td {
display: table-cell;
}

Then on the table and cell, I use:

Syntax: [ Download ] [ Hide ]
echo "<table cellpadding='10' width='900' style='border-collapse:collapse;table-layout:fixed'>"
echo '<td valign="top" style="white-space:pre-wrap;white-space:-moz-pre-wrap !important;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word;word-break:normal; width:99%; overflow-x:auto;">' . $result['description'] . '</td>';
 

Author:  pbs [ Mon Oct 13, 2014 2:58 am ]
Post subject:  Re: td word wrap in all browsers

use PHP wordwrap() function instead

Syntax: [ Download ] [ Hide ]
e.g.
$newtext = wordwrap($text, 20, "<br />\n");
 

Author:  cjkeane [ Mon Oct 13, 2014 2:02 pm ]
Post subject:  Re: td word wrap in all browsers

so you think i should replace all of this: style="white-space:pre-wrap;white-space:-moz-pre-wrap !important;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word;word-break:normal; width:99%; overflow-x:auto;" with just the php wordwrap?

Author:  Celauran [ Mon Oct 13, 2014 2:51 pm ]
Post subject:  Re: td word wrap in all browsers

No. That wraps a string at a fixed number of characters which is not only unhelpful for variable width fonts, but not great for responsive either. Can you show an example of the problem on JSFiddle or Codepen or something?

Author:  Celauran [ Mon Oct 13, 2014 2:51 pm ]
Post subject:  Re: td word wrap in all browsers

Also, isn't there a <tr> missing in there?

Author:  cjkeane [ Mon Oct 13, 2014 3:33 pm ]
Post subject:  Re: td word wrap in all browsers

i only gave you the lines of code which i was inquiring about. i just omitted the tr's

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/