views:

69

answers:

3

How can I split a long word/url at a certain point when displaying it in a html div?

It should be like:

thisisareallylongwordt 
hatneedstobebroken her
e or something like th
at.
A: 

You need to manually insert <br> tags:

thisisareallylongwordt<br>
hatneedstobebroken her<br>
e or something like  th<br>
at

There is afaik no CSS solution as much as one would want one.

Edit: As Raoul suggested the soft-hyphen &shy; works too. Did not know that existed myself.

FK82
+2  A: 

if you are wanting the word to break at the edge of the div rather than to overflow it use

div {word-wrap:break-word}
lnrbob
I think he said "at a certain point". Good pointer nonetheless.
FK82
A: 

Do you want a static word wrap or something more dynamic as the size of the div changes? If you want the latter then you will probably want to use javascript. The jQuery library has a word-wrap plugin:

http://plugins.jquery.com/project/wordWrap

Dan

Dan Kendall
That plugin is for `<textarea>` tags.
Amber
Ah, thanks for the gen - that'll teach me to do some quick googling before work.
Dan Kendall