CSS 如何强制`span`不在行尾换行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7015317/
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
How can I force a `span` to not wrap at the end of a line?
提问by Shamoon
If it's a really long line of text, I want it to extend without wrapping
如果它是一行很长的文本,我希望它在不换行的情况下扩展
回答by zzzzBov
Try
尝试
span
{
white-space: pre;
}
or any other value that fits from the w3c spec:
normal
This value directs user agents to collapse sequences of white space, and break lines as necessary to fill line boxes.pre
This value prevents user agents from collapsing sequences of white space. Lines are only broken at preserved newline characters.nowrap
This value collapses white space as for 'normal', but suppresses line breaks within text.pre-wrap
This value prevents user agents from collapsing sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.pre-line
This value directs user agents to collapse sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.
normal
此值指示用户代理折叠空白序列,并根据需要断开线条以填充行框。pre
此值可防止用户代理折叠空白序列。仅在保留的换行符处断行。nowrap
这个值像'normal'一样折叠空白,但抑制文本中的换行符。pre-wrap
这个值防止用户代理折叠空白序列。在保留的换行符处断行,并根据需要填充行框。pre-line
该值指示用户代理折叠空白序列。在保留的换行符处断行,并根据需要填充行框。
You should also be aware that there is limited IE support for some of the listed options.
WARNING, Cross-browser content messiness: You could replace all spaces in the line with
警告,跨浏览器内容混乱:您可以将行中的所有空格替换为
回答by AlexC
CSS:
CSS:
span
{
white-space:nowrap
}