开发者

Making a piece of text non-breaking?

开发者 https://www.devze.com 2022-12-21 11:12 出处:网络
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

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-inside and such, but it doesn't seem to do anything in firefox.


Use the white-space property:

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; }


Adding this for completeness:

If you do not want to use CSS, you could use <nobr>text with space</nobr> - reference here

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 structure use <em>, <strong> and <span class="">.


bootstrap 4 has a class="text-nowrap"

more here https://getbootstrap.com/docs/4.0/utilities/text/#text-wrapping-and-overflow

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号