【问题标题】:How do I keep a span from being at the end of a line?如何防止跨度位于行尾?
【发布时间】:2013-11-22 01:45:05
【问题描述】:

假设我有一个段落元素,其中包含几种不同类型的跨度,这些跨度将 css 样式委托给类。如果我在文本的其余部分中包含数字作为位置标记以便于参考,我该如何防止这些数字出现在换行的末尾?

例如

1 This is some text that
wraps. 2 I don't want any
of these numbers 3 to end
up at the end of one of these
lines. For this example, 4
this number shouldn't be at
the end of the line.

对不起,如果这有点草率,但这是我能想到的唯一描述它的方式。这些数字中的每一个都包含在其自己的跨度中,并为其提供了一个类名。我想找到正确的 css 或诸如此类的东西,以防止它成为行中的最后一个对象。

我考虑在数字跨度上使用一些右边距长度,然后在下一个文本跨度的开头添加负边距,但我希望这是一个可以涵盖所有情况的灵活解决方案。

谢谢

【问题讨论】:

    标签: html css formatting styles


    【解决方案1】:

    如果您在数字和第一个单词之间放置一个不间断空格 ( ),那么浏览器将使用下一个单词将其换行。像这样:(demo)

    1 This is some text that wraps. 2 I don't want anyof these numbers 3 to end up at the end of one of these lines. For this example, 4 this number shouldn't be at the end of the line.
    

    【讨论】:

    • 天哪。我使用了大量的不间断空格,但我从来没有因为它的名字是“不间断”的原因而绑定。粉笔一记不注意。哈哈,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-07
    • 2011-11-10
    • 2015-09-21
    • 1970-01-01
    • 2019-07-01
    • 1970-01-01
    相关资源
    最近更新 更多