如何避免最后一行的一个单词与CSS? [英] How can I avoid one word on the last line with CSS?

查看:104
本文介绍了如何避免最后一行的一个单词与CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设文字在HTML网页上显示如下(只有一个字太长,不适合一行):

Suppose a text shows up as follows on an HTML page (just one word too long to fit on one line):

Lorem ipsum dolores amet foo
bar

如何使用CSS避免最后一个字出现在最后一行,强制两个(或更多)?

How can one avoid with CSS that the last word appears on the last line, and force two (or more)?

Lorem ipsum dolores amet
foo bar


推荐答案

我不认为你可以在纯CSS。

I don't think you can do this in pure CSS.

您必须在最后两个字词之间插入一个不间断的空格:

You would have to either put a non-breaking space in between the last two words:

foo bar

code> span :

or put the last two words into a span:

<span style="white-space: nowrap">foo bar</span>

这篇关于如何避免最后一行的一个单词与CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆