0

This is my html:

<div class="targetdiv">My Text that come out of div</div>
<style>
  .targetdiv{
     width: 24%;
     border: 1px solid red;
  }
</style>

with the above design my text come out of div. But if I change the width and use pixel instead of percentage every thing would be OK:

<style>
  .targetdiv{
     width: 190px;
     border: 1px solid red;
  }
</style>

So how could I use percentage in width and my text remain inside of div? any suggestion?

Saeid Alizade
  • 853
  • 3
  • 9
  • 18

1 Answers1

0

You can use this class:

<style>
.targetdiv {
       width: 190px;
       border: 1px solid red;
       white-space: pre-wrap;      /* CSS3 */   
       white-space: -moz-pre-wrap; /* Firefox */    
       white-space: -pre-wrap;     /* Opera <7 */   
       white-space: -o-pre-wrap;   /* Opera 7 */    
       word-wrap: break-word;      /* IE */
    }
</style>

Original answer was posted by Aaron Bennett here: Is there a way to word-wrap long words in a div?

And here is a working fiddle:

http://jsfiddle.net/LRpve/

Community
  • 1
  • 1