也许这是不可能的,但我想知道是否有一种方法可以在打断单词之前自动在没有空格的长字符串末尾插入一个连字符?这jsfiddle演示了我遇到的问题。谢谢。
table {
width:200px;
word-wrap:break-word;
table-layout: fixed;
}
<table>
<td>Pneumonoultramicroscopicsilicovolcanoconiosis</td>
</table>
最佳答案
对于 webkit 浏览器,这应该可以工作:
table
{
width: 200px;
word-break: break-word;
-webkit-hyphens: auto;
}
这适用于 iOS Chrome,但不适用于 OS X Chrome。 This博客文章解释了适用于其他浏览器的解决方案,但它在 OS X Chrome 上仍然不适用于我。
那里显示的解决方案是:
table
{
-ms-word-break: break-all;
word-break: break-all;
// Non standard for webkit
word-break: break-word;
-webkit-hyphens: auto;
-moz-hyphens: auto;
hyphens: auto;
}
如果这在您需要的浏览器中不起作用,请查看 hyphenator - 一个 javascript 实用程序,可以更好地满足您的需求。
关于html - 在分词前添加连字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16498154/