1

I have this div:

<div class="text">
    Thisismytextwontgoinanewparagraph
</div>

with this CSS:

.text
{
    background-color:red;
    width:100px;
}

As you can see in this JSFiddle, the text goes outside of the div.

Is there a way in CSS to force wrapping for a text without spaces (such as a hyperlink)?

Paul D. Waite
  • 93,468
  • 54
  • 192
  • 264
markzzz
  • 45,272
  • 113
  • 282
  • 475

1 Answers1

4

you could try this, but it's not very pretty:

.text
{
    background-color:red;
    width:100px;
    word-wrap: break-word;
}

http://jsfiddle.net/esGEn/1/

dax
  • 10,497
  • 7
  • 51
  • 85
  • The code breaks the string at arbitrary points. This is seldom acceptable, and surely not for URLs (which is what the question probably means by “such as a hyperlink”). – Jukka K. Korpela Oct 07 '13 at 14:12
  • thus, " but it's not very pretty" – dax Oct 07 '13 at 14:13
  • You can make certain elements unbreakable with `white-space:nowrap`, like in this fiddle: http://jsfiddle.net/keaukraine/JsNgQ/ – keaukraine Oct 07 '13 at 14:17