Is there a way to make hyphens work on text with <span>
elements for highlighting without breaking the algorithm? I don't want a workaround like ­
.
https://i.sstatic.net/JGl1M.png
The Code (sandbox: https://codepen.io/anon/pen/ayzxpM):
.limit {
max-width: 50px;
hyphens: auto;
font-size: 20px;
background-color: #eee;
}
span {
color: red;
}
<div class="limit">
<p>
Appletreefruitthing
</p>
<p>
Apple<span>tree</span>fruitthing
</p>
</div>
Using the lang attribute
Can adding the lang attribute as Vadim Ovchinnikov suggested (
<div class="limit" lang="en">
) improve results on certain platforms and browsers? On Windows 10, Firefox 54, here is an example:
https://i.sstatic.net/lrDd4.png
However, it still seems to have bugs. The hyphen color should be black and there are missed opportunities for line breaks between words, ignoring the set max-width
for the container.