5

I have a very long text without space. For example,

<div style="width: 179px">
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
</div>

I want to split this text into lines with maximum width 179px. Do you know how to do that?

gilly3
  • 87,962
  • 25
  • 144
  • 176
Rasika H
  • 119
  • 2
  • 2
  • 5

8 Answers8

7

Use CSS.

word-wrap: break-word;
duri
  • 14,991
  • 3
  • 44
  • 49
2

This won't work in ALL browsers, but it should at least work for most (this is CSS):

#your_div {
  white-space: pre-wrap;
  white-space: -pre-wrap;
  white-space: -o-pre-wrap;
  word-wrap: break-word;
}
Blender
  • 289,723
  • 53
  • 439
  • 496
1

I think the css3 word-wrap:break-word property will sort this out for you.

JHolyhead
  • 984
  • 4
  • 8
1

Add the style word-wrap: break-word; to the div. It is a CSS3 property that works in ALL browsers (even IE5!)

Chris G.
  • 3,963
  • 2
  • 21
  • 40
1

You can apply the CSS style "word-wrap: break-word;" to the element.

Here's an example

You can also apply WBR tags to the word and it will split it according to those tags.

Here's an example of that
Learn more about wbr tags

Cory Danielson
  • 14,314
  • 3
  • 44
  • 51
1

I would suggest word-wrap: break-word

simoncereska
  • 3,035
  • 17
  • 24
1

Just see below the link,

http://jsfiddle.net/xj56D/2/

anglimasS
  • 1,304
  • 2
  • 16
  • 41
0

Use word-wrap: break-word:

http://jsfiddle.net/gilly3/fS5cX/

gilly3
  • 87,962
  • 25
  • 144
  • 176