tags:

views:

176

answers:

3

Hi,

If I have a very long string (without spaces!) can I force the browser to line break it, for example, in a table's td via CSS. Width does not seem to have any effect. Thanks!

Christian

PS:

I know it is very unlikely that someone submits long strings without space but you never know ...

I tried:

.gridrow td
{
    padding:1em;
    text-align:center;
    word-wrap: break-word; 
}

and I use FF as my browser. word-wrap only seems to be used in css3???

A: 

i think there wordwrap element. search for the wordwrap.

word-wrap: break word

EDITED

REF Word-wrap in a html table

it suggest that there's no good way of doing this.

Salil
does not seem to help.
csetzkorn
If there _is_ such an element, it would be semantically incorrect to use it.
Eric
+1  A: 

I think what you mean is in CSS:

#id
{
  max-width: 100px; /*or whatever*/
  word-wrap: break-word;
}

Tested on your site with Firebug, it works.

Reference article.

Kyle Sevenoaks
Thanks. I tried this and it does not work.
csetzkorn
Which browser are you testing in? Havbe a live example?
Kyle Sevenoaks
Which browser are you using?
Eric
Please see edit in original question:http://www.zoonosis.ac.uk/ICONZ/ResearchProjects/PublicResearchProjects?page=1
csetzkorn
not working for me either.
Salil
Updated my answer, you need to specify max-width.
Kyle Sevenoaks
Thanks this works fine!
csetzkorn
Glad to help :)
Kyle Sevenoaks
I am no css expert but word-wrap is css3 specific is this actually suppose to be supported/official?
csetzkorn
Most modern browsers support it, Gecko and Webkit browsers for sure, I didn't test it in IE, and I wouldn't be surprised if it didn't work. CSS3 is unofficially launched but a lot of the functionality of it has already been implemented in modern browsers, like the CSS transitions in Webkit browsers. So while CSS3 is unofficial at the moment, browser developers are working hard to implement as much of it as they can.. Someone else might be able to elaborate more. www.css3.info for more information.
Kyle Sevenoaks
Word-wrap was started by IE, so yes it would support it.
D_N
+1  A: 

Tables are a special case. They'll keep on expanding if they can, so as not to obscure any content; you can't use overflow:hidden on them either. Here are some options:

  1. Use an optional breaking character. (Source: http://www.quirksmode.org/oddsandends/wbr.html ) If you can control insert a character like &shy; or <wbr> programatically into long strings, this may be a solution.

  2. Perhaps preferably, depending on your situation, you can limit the table to use strict widths, at which point it should obey your rule:

    .grid {
      table-layout:fixed;
      width:600px;
    }
    
D_N
Thanks. The css does not work for me. I think I might implement a business rule which prevents long words (what is too long haha). Maybe I am splitting hairs here.
csetzkorn
It worked for me on your site via Firebug.
D_N