Alexis
Alexis

Reputation: 25233

Wrap a word without spaces in a div

I have a div that is of fixed width, 300px. I have user inputed text that needs to go into the div. The issue is, is that people are putting the word "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" into the div. This causes the text to exceed the width of the div. What I would like is for the text to wrap even if there is no spaces in the words. Is there a way to do this with css? I tried the css white-space property but it was not working.

If anyone has a solution or a point in the the right direction would be wonderful.

Upvotes: 3

Views: 3076

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201866

There is no way to do this properly, with the current state of the art. Line breaking rules are complex and vary by language.

Using word-wrap:break-word or some of its va riants arbitrarily breaks a string of characte rs and almost certainly breaks the rules of th e language and confuses people.

Upvotes: 1

Joel Eckroth
Joel Eckroth

Reputation: 2534

Try this:

word-wrap:break-word;

Upvotes: 9

Related Questions