This question already has an answer here:
I have this piece of HTML
<div id='permalink_section'>
<a href="here goes a very long link">here goes a very very long link</a>
</div>
with, for now, this CSS
div#permalink_section { width: 960px }
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?
The following is a cross browser compatible solution.
Check working example at http://jsfiddle.net/5zsqP/1
wrap link inside another div with smaller width
if you're okay with css3, there's a property for that:
overflow:hidden
seems to be the key to making an element ofsize:auto
break-word
correctly
http://jsfiddle.net/9jDxR/
That example includes a left float as I was trying to achieve a media-object like layout.
Unfortunately if you try to use
table-cell
elements it breaks again :(or
or use javascript to truncate the length of the link's text, replacing the end with "..."
Working example of the JS method: http://jsfiddle.net/fhCYX/3/
You could also wrap each letter of the link in
<span></span>
using javascript for example.But I would go for the css3 approach.
2017 Disclaimer: This is not a good solution and I never said it was. If you still feel the need to comment, please at least read the previous comments