Html 使一段文本不间断?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2359443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making a piece of text non-breaking?
提问by Earlz
say I have a piece of text like this
说我有一段这样的文字
Hello I am some text Hello I am some text Hello I am some text Hello I am some text I do not wish to be broken on new lines
你好我是一些文字 你好我是一些文字 你好我是一些文字 你好我是一些文字我不希望在新行中被打破
Consider the above paragraph. I want for the bolded part to not be broken across a new line if possible. As in, I want it to break if it would require a scrollbar or something, but not break if it is possible to insert a page-break before or after that piece of text so that it can fit on one line.
考虑上面的段落。如果可能的话,我希望粗体部分不要被换行。就像,我希望它在需要滚动条或其他东西时中断,但如果可以在该段文本之前或之后插入分页符以使其适合一行,则不会中断。
How is this possible? I have tried things like page-break-insideand such, but it doesn't seem to do anything in firefox.
这怎么可能?我已经尝试过诸如此类的事情page-break-inside,但它似乎在 Firefox 中没有做任何事情。
回答by cletus
Use the white-spaceproperty:
使用white-space属性:
Hello I am some text Hello I am some text Hello I am some text
Hello I am some text <span class="nobr">I do not wish to be
broken on new lines</span>
with:
和:
span.nobr { white-space: nowrap; }
回答by BananaAcid
Adding this for completeness:
为了完整性添加这个:
If you do not want to use CSS, you could use <nobr>text with space</nobr>- reference here
如果你不想使用 CSS,你可以使用<nobr>text with space</nobr>- 参考这里
For pure text blocks, i believe not-anymore-depricated html formatting tags like <i>, <b>, <nobr>and alike are valid for use.
For content relating to the site structureuse <em>, <strong>and <span class="">.
对于纯文本块,我相信不再被贬低的 html 格式标签(如<i>、<b>、<nobr>等)都可以使用。
对于与站点结构相关的内容,请使用<em>,<strong>和<span class="">。
回答by Yevgeniy Afanasyev
bootstrap 4 has a class="text-nowrap"
bootstrap 4 有一个 class="text-nowrap"
more here https://getbootstrap.com/docs/4.0/utilities/text/#text-wrapping-and-overflow
更多在这里https://getbootstrap.com/docs/4.0/utilities/text/#text-wrapping-and-overflow

