I have a text inside a div
with a hyphen in it. When the div
gets too small, the text overflows instead of breaking at the hyphen.
I tried a bit with word-break
and overflow
, but couldn't figure out how to make the text break only at the hyphen. Here is an example of what is happening, and what I am trying to achieve.
div{
width:70px;
border:1px solid;
}
<b>How it is now </b>
<div> bla bla-blablabla</div>
<br>
<b> What should happen: </b>
<div> bla bla-<br>blablabla</div>
Edit for the duplicate question: The answers given there are wrong.
- The best (by votes) answer suggests replacing hyphens by
­
. This is incorrect, since those hyphens will NOT show up when there is no line break. - The second answer suggests
<wbr>
, but this is not supported in all browsers. - The third best answer suggests CSS word-wrapping, which does not make it break at hyphens.