203

I have a fixed width div on my page that contains text. When I enter a long string of letters it overflows. I don't want to hide overflow I want to display the overflow on a new line, see below:

<div id="textbox" style="width:400px; height:200px;">
dfssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssfddddddddddddddddddddddsdffffffffffffffffsdffffffffffffffffdfssssssssssssdf
</div>

Is there anyway to disable overflow and put the overflowing text on a new line??? Twitter does something like this but I can't figure it out with CSS it's possible they are using Javascript.

Can anybody help with this??

Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
user342391
  • 7,569
  • 23
  • 66
  • 88

4 Answers4

346

Just add

white-space: initial;

to the text, a line text will come automatically in the next line.

Jan
  • 2,060
  • 2
  • 29
  • 34
Pankaj Verma
  • 3,469
  • 1
  • 9
  • 2
318
word-wrap: break-word

But it's CSS3 - http://www.css3.com/css-word-wrap/.

Community
  • 1
  • 1
mikemerce
  • 3,512
  • 1
  • 16
  • 9
6

Try the <wbr> tag - not as elegant as the word-wrap property that others suggested, but it's a working solution until all major browsers (read IE) implement CSS3.

casablanca
  • 69,683
  • 7
  • 133
  • 150
4

Well, you can stick one or more "soft hyphens" (&#173;) in your long unbroken strings. I doubt that old IE versions deal with that correctly, but what it's supposed to do is tell the browser about allowable word breaks that it can use if it has to.

Now, how exactly would you pick where to stuff those characters? That depends on the actual string and what it means, I guess.

Pointy
  • 405,095
  • 59
  • 585
  • 614