I have the following problem:
I have a simple div container with the text "International" inside. I want the word to break when overflowing the container width.
How do I make it, so that there’s a "-" when the word breaks?
I added the attributes "hyphens: auto" and "word-wrap: break-word" to the div container. Now the word does break, but it doesn’t add the "-" character when breaking. I also tried adding "hyphenate-character: "-";" but this doesn’t seem to help as well.
3
Answers
hyphens: auto
requires the language to be setIf you try this second snippet in Chrome, Safari and Firefox you’ll notice (as you resize the browser window) that Chrome and Safari seem to always break at the first opportunity (in-ternational) whereas Firefox works much more as you would expect; it will break at different locations depending how much space there is on the line.
Because browser support for this seems to be a bit of a minefield, you could always look at a Javascript library called Hyphenopoly which claims to sort this out for all browsers.
However for a simple
<div>
containing a single word, I think you’re much better off just using the­
escape sequence to insert a soft hyphen.You can add a soft hyphen where you’d prefer the text to break:
Apart from mentioned prerequisition of explicit
lang
attribute (or other mean browser gets language of the elemen), apparently there is important distinction in letter casing: browses refuse to break words beginning with uppercase letter, presumably because it might be a name where syllable / semantic boundaries are not known:(Firefox.)