Html 跨度上的空白 nowrap

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27013259/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:05:26  来源:igfitidea点击:

whitespace nowrap on span

htmlcsswhitespacenowrap

提问by Mina

In this case:

在这种情况下:

<td>
       Some Text
       <span class="Icon"></span>
</td>

I want to get the line break when necessary on my Text but I don't want my span to get on a new line, I want it to always stick to part of the text. How can I do it?

我想在必要时在我的文本上换行,但我不希望我的跨度出现在新行上,我希望它始终坚持文本的一部分。我该怎么做?

Thanks,

谢谢,

回答by Mina

How I solved my problem by putting one span into the other:

我如何通过将一个跨度放入另一个跨度来解决我的问题:

<table style="width:100px">
<tr>
    <td>
        I am Showing you what <span style=" white-space: nowrap;">I meant
        <span> Blah Blah </span></span>
    </td>

</tr>

Check JSFiddle.

检查JSFiddle

回答by Jukka K. Korpela

Replace all whitespace before the spanwith a single no-break space (if you want some spacing to appear between your text and whatever rendering you have styled for the span; if no spacing is desired, omit the &nbsp;).

span单个不间断空格替换 之前的所有空白(如果您希望在文本和为 设置样式的任何渲染之间出现一些间距span;如果不需要间距,请省略&nbsp;)。

<td>
       Some Text&nbsp;<span class="Icon"></span>
</td>