I have this piece of code:
div#permalink_section { width: 960px }
<div id='permalink_section'> <a href="here goes a very long link">here goes a very very long link</a> </div>
The link text can be very long and it overflows the div when it's length does exceed the div width. Is there a way to force the link to break and go on the next line when its width exceeds the div width?
You should use display: table; It will shrink to the size of it's contents and can also be centered and positioning without having to assign a given width.
What is the difference between “word-break: break-all” versus “word-wrap: break-word” in CSS ? The word-break property in CSS is used to specify how a word should be broken or split when reaching the end of a line. The word-wrap property is used to split/break long words and wrap them into the next line.
The following is a cross browser compatible solution:
#permalink_section { white-space: pre-wrap; /* CSS3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */ }
From How do I wrap text with no whitespace inside a <td>?
Check working example here.
If you're okay with CSS3, there's a property for that:
word-wrap:break-word;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With