这个问题在这里已经有了答案:
How to stop text from taking up more than 1 line?
(5 个回答)
3个月前关闭。
有没有办法到不是 在特定点打断一个词?
类似于 ­
的反面?
我已将文本设置为 hyphens: auto;
但在某个特定点,这个词会中断,这是不正确的。我已经设置了 ­
在单词的多个位置,但它仍然在错误的位置中断。
我想在 html 中插入一些东西(没有 css 或任何东西,因为它必须工作编辑),告诉浏览器在这一点上无论如何都不要中断。
最佳答案
AFAIK 没有明确的 HTML 特殊字符来执行此操作。
一种解决方法可能是指定您的整个内容在任何地方都可破解,并将单词中不可破解的部分包装在 span
中。没有断词。
然后,您可以在编辑器中决定希望该词停止的位置:
.breakable {
word-break: break-all;
}
.unbreakable {
word-break: normal;
color: red;
}
<div class="breakable">Browser can break anywhere here, but not where I decide: on this <span class="unbreakable">specificsuperlong</span>wordofmine, the red part is unbreakable. </div>
<div class="breakable">If I want to decide a special position it can only split on, I wrap my special <span class="unbreakable">unbrea</span>k<span class="unbreakable">able</span> in two spans.</div>
关于html - 对面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68271266/