I am trying to wrap text in a fixed layout but it doesn't work when the text contains slashes.
Can this be fixed without inserting spaces from Javascript (pure CSS)?
jsfiddle:
http://jsfiddle.net/HgBhk/1/
Not working:
<div style="display:table; width:170px; background-color:cyan;">
<div style="display:table-row">
<div style="display:table-cell;word-wrap: break-word;">abfdbfdbfdb/dfbfdbdfbfbf/bdffbdbfdfbddfbdfbdfb</div>
<div style="display:table-cell; width:34px; background-color:red;">xxxxx</div>
</div>
</div>
</br>
Working:
<div style="display:table; width:170px; background-color:cyan;">
<div style="display:table-row">
<div style="display:table-cell;word-wrap: break-word;">abfdbfdbfdb dfbfdbdfbfbf bdffbdbfdfbddfbdfbdfb</div>
<div style="display:table-cell; width:34px; background-color:red;">xxxxx</div>
</div>
</div>
Insert either a <wbr>
tag or a zero-width space ​
after each occurrence of a slash or other character that should be treated as allowing direct line break after it. The choice between these alternatives is a bit complicated, but since your code already fails to work on old versions of IE, you might just as well ignore them here too, and this would make ​
the right choice. That is, you would write e.g.
abfdbfdbfdb/​dfbfdbdfbfbf/​bdffbdbfdfbddfbdfbdfb
The issue is at the character level, not a matter of styling.
A string containing no whitespace characters is normally indivisible in wrapping and should be that way, unless you can reliably make browsers either break at acceptable breaking points or hyphenate properly and use word division. A setting like word-wrap: break-word
is meant for exceptional cases, emergency breaks when there is no good way to control wrapping and there is a need to avoid overflow.
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