38

I am having issues with wrapping text. I am generating some hexencoding encryption and the output is too long like:

827938828ey823876te37257e5t328er6367r5erd663275e65r532r6s3624e5645376er563rdr753624e544341763r567r4e56r326r5632r65sr32dr32udr56r634r57rd63725

and it continues. When I put it inside a div, it won't wrap it even if I assign a specific width, because they are all together. I want it to continue from the next line if the div is not wide enough for one line.

How can I do that?

Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
tugberk
  • 57,477
  • 67
  • 243
  • 335
  • apperently stackoverflow.com is implementing what I need here. it continues from second line. when I look at this page's source code, I see the following for post-text: width: 660px; font-size: 107%; margin-bottom: 5px; margin-right: 5px; line-height: 130%; – tugberk Feb 25 '11 at 17:13

4 Answers4

65

You can't wrap that text as it's unbroken without any spaces. You need a JavaScript or server side solution which splits the string after a few characters.

EDIT

You need to add this property in CSS.

word-wrap: break-word;

adarshr
  • 61,315
  • 23
  • 138
  • 167
18

I have found something strange here about word-wrap only works with width property of CSS properly.

#ONLYwidth {
  width: 200px;
}

#wordwrapWITHOUTWidth {
  word-wrap: break-word;
}

#wordwrapWITHWidth {
  width: 200px;
  word-wrap: break-word;
}
<b>This is the example of word-wrap only using width property</b>
<p id="ONLYwidth">827938828ey823876te37257e5t328er6367r5erd663275e65r532r6s3624e5645376er563rdr753624e544341763r567r4e56r326r5632r65sr32dr32udr56r634r57rd63725</p>
<br/>
<b>This is the example of word-wrap without width property</b>
<p id="wordwrapWITHOUTWidth">827938828ey823876te37257e5t328er6367r5erd663275e65r532r6s3624e5645376er563rdr753624e544341763r567r4e56r326r5632r65sr32dr32udr56r634r57rd63725</p>
<br/>
<b>This is the example of word-wrap with width property</b>
<p id="wordwrapWITHWidth">827938828ey823876te37257e5t328er6367r5erd663275e65r532r6s3624e5645376er563rdr753624e544341763r567r4e56r326r5632r65sr32dr32udr56r634r57rd63725</p>

Here is a working demo that I have prepared about it. http://jsfiddle.net/Hss5g/2/

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
immayankmodi
  • 8,210
  • 9
  • 38
  • 55
4
white-space: pre-wrap

is what worked for me for <span> and <div>.

Hemang
  • 26,840
  • 19
  • 119
  • 186
2

You can use the following

p{word-break: break-all;}

        <p>LoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolorLoremipsumdolor</p>
Navneet Kumar
  • 623
  • 1
  • 6
  • 16