行尾有一个字母(对齐) [英] One letter word on the end of line (justify)

查看:75
本文介绍了行尾有一个字母(对齐)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果在文本行末尾有一个字母单词怎么办?

I wonder what I can do if I have one letter word on the end of text line, for example:

"Hello my name is John Smith, and I
am a freshman!"

如何将"I"移至下一行,并证明整行的合理性?因为当我放< br> 时,便证明崩溃.

How can I move "I" to the next line, and have justified the entire line? Because when I put <br> then justify crashes.

这是jsfiddle http://jsfiddle.net/P3xYv/

Here's jsfiddle http://jsfiddle.net/P3xYv/

推荐答案

如果您在两个单词之间使用NO-BREAK SPACE U + 00A0,而不是普通的空格(如空格或换行符),浏览器会将这些单词保持在一起,一行.示例:

If you use a NO-BREAK SPACE U+00A0 between two words, instead of normal whitespace (like space or line break), browsers will keep those words together, on one line. Example:

"Hello my name is John Smith, and I&nbsp;am
a freshman!"

在这里,我使用了命名字符参考& nbsp; ,但是如果您知道如何在创作环境中键入该字符并正确声明了该字符,也可以使用NO-BREAK SPACE本身.字符编码.在大多数编辑程序中,"NO-BREAK SPACE"看起来就像一个普通空间.

Here I have used the named character reference &nbsp;, but you can also use the NO-BREAK SPACE itself if you know how to type it in your authoring environment and have properly declared the character encoding. In most editing programs, NO-BREAK SPACE looks just like a normal space.

这与文本对齐方式无关.在过去,浏览器过去常常将NO-BREAK SPACE视为不可拉伸.但是如今,它被视为有理有据的空间,也就是说,它获得了增加间距的份额.

This is independent of text justification. In the old days, browsers used to treat NO-BREAK SPACE as non-stretchable in justification. But nowadays it is treated like space in justification, i.e. it gets its share of added spacing.

如果您希望单词之间具有不间断且不可拉伸的空间,则需要一种更复杂的方法.您可以使用U + 2005的FOUR-PER-EM SPACE或其他一些固定宽度空格,然后将单词包装在元素中,其中禁止换行与HTML或CSS.例如,您可以编写< nobr> I&#x2005; am</nobr> ,而不是 I& am ,或更笨拙但符合标准"",< span style ="white-space:nowrap"> I&#x2005; am</span> .但是,我们不能保证这会在将来奏效.规范中没有要求浏览器以这种方式支持固定宽度的字符(但这是一种简单自然的实现,也是当前的实现).

If you’d like to have a non-breaking non-stretchable space between words, you’d need a more complicated approach. You would use U+2005 FOUR-PER-EM SPACE or some other fixed-width space and you wrap the words in an element where line breaking is forbidden with HTML or CSS. For example, instead of I&nbsp;am you would write <nobr>I&#x2005;am</nobr> or, more clumsily but conforming to "standards", <span style="white-space: nowrap">I&#x2005;am</span>. There is no guarantee that this will work in the future, though; there is no requirement in specifications that browsers support fixed-width characters this way (but this is a simple and natural implementation, and the current one).

这篇关于行尾有一个字母(对齐)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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