CSS中有没有一种方法可以避免寡妇而不必使用其他HTML?

时间:2019-04-16 21:40:55

标签: html css content-management-system whitespace textwrapping

我有一行在内容管理系统中管理的副本。 CMS不允许HTML或特殊字符,例如&nbsp;<span>

我试图弄乱边距和填充,但是什么也没能给我预期的结果。

这是呈现文本的方式:

<h1>This is an example of the headline.</h1>

我想阻止一个寡妇(一个孤单的单词出现在文本块的底部),因此当行确实中断时,它将最后两个单词视为1个单词。

例如,“标题”将中断至下一行,而不仅仅是“标题”。

有没有办法单独在CSS中做到这一点?

我很想在CSS中看到“空白:没有寡妇”,但这并不存在。

1 个答案:

答案 0 :(得分:0)

Short answer: no, there's no way to do this that i know of.

if you could wrap those last two words in a span with a no-wrap style on it that might work. But I see you can't add a span in your CMS.

One thing you could do: set the width of the h1 in em units, so that its width is proportionate to the size of the text. This way you can set a width that forces the title to break where you want it to, and that width will scale with the text.