tags:

views:

176

answers:

2

Hello everyone,

I have an html table, and one column (<td>) has long text, so I want to set the max-width of the column -- so that if text is longer than the max-width, the text could auto-wrap to next line. I have tried to use css max-width style on related TD element of the column, something like "max-width:100px", but it does not work (text still very long and not auto-wrap to next line if it is very long).

Any ideas what is wrong or any solution reference code? I am using IE 8 on Windows 7.

thanks in advance, George

+2  A: 

You need to add the CSS3 property word-wrap: break-word;.

BalusC
along with max-width?
George2
Thanks, your solution works!
George2
+1  A: 

Old html td width will work in IE 8 for that... But you want maximum-width, not a width... besides the extra html attribute needed for each cell.

S.gfx
"But you want maximum-width, not a width" -- what I need is simple, just make long text automatically wrap to next line, similar to automatic-wrap feature of notepad. Any solutions?
George2
Yep, and the solution given by someone above will do. (Gotta check on IE8 , as I guess is your target) Obviously, css3 wont apply in IE6,for sure. My solution works, but is not flexible, you need fixed width on tds and probably also on the table. Which is no fun. break-word that he mentioned is the only way if what you try to break is words, older css properties wont break for example long registry key strings with no spaces. Anyway, older css to do wrapping:http://www.w3schools.com/css/pr_text_white-space.asphttp://www.quirksmode.org/css/whitespace.html(browsers support table)
S.gfx
Another solution I've used sometimes is embed inside a div, or span (with display:block or not, depending on what is needed), to which I apply whicever properties... can be the trick, in some cases.
S.gfx