0

I have an big Problem that I would like to solve.

PROBLEM

  • One line Strings that be displayed over the element width

CODE EXAMPLE

.box {
  width:150px; 
  border: 2px solid black;
}
<div class="box">
  <p>THIS IS A LONG STRING<br>
  BUT_THIS_WOULD_BE_THE_PRBLEM_WHEN_A_STRING_HAVE_NO_SPACES!!!!!!!!!!!!!!!!!!!!!!!!!!!!</p>  
</div>

Maybe someone know how I can display the Text likes this.(Only in JS,JQuery,CSS)

WANTED RESULT

.box {
  width: 150px;
  border: 2px solid black;
}
<div class="box">
  <p>THIS IS A LONG STRING<br>AND_THIS_IS_THE-<br>CONVERTED_STR-<br>ING
</div>
Andrew
  • 2,810
  • 4
  • 18
  • 32
Daniel O.
  • 196
  • 2
  • 16

1 Answers1

1

Maybe you should use word-wrap

Allow long words to be able to break and wrap onto the next line:

.box {
  width:150px; 
  border: 2px solid black;
  word-wrap: break-word;
}
<div class="box">
  <p>THIS IS A LONG STRING<br>
  BUT_THIS_WOULD_BE_THE_PRBLEM_WHEN_A_STRING_HAVE_NO_SPACES!!!!!!!!!!!!!!!!!!!!!!!!!!!!</p>  
</div>
Dillinger
  • 1,823
  • 4
  • 33
  • 78