HTML 连字符处没有换行符

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

HTML no line break at hyphens

html

提问by Kirk Strobeck

So I have the text e-commerceand I don't want the line to wrap at the dash.
How would I restrict wrapping for that text line?

所以我有文本e-commerce,我不希望该行在破折号处换行。
我将如何限制该文本行的换行?

回答by Paul Sham

You could use CSS: white-space: nowrap;.

你可以使用 CSS: white-space: nowrap;.

Example: Wrap the text in a span with that CSS declaration.

示例:使用该 CSS 声明将文本包裹在一个 span 中。

<span style="white-space: nowrap;">e-commerce</span>

<span style="white-space: nowrap;">e-commerce</span>

回答by Malvolio

Use the non-breaking hyphen: &#8209;

使用不间断连字符: &#8209;

回答by David Wolever

Wrap it in the <nobr>…</nobr>tag, or if you care out the validity of your HTML, set the white-space: nowrap;style.

将其包装在<nobr>…</nobr>标签中,或者如果您关心 HTML 的有效性,请设置white-space: nowrap;样式。

回答by Robert Siemer

There is this non-breaking hyphen (copy and paste it):?or use &#8209;or &#x2011;

有这个不间断的连字符(复制并粘贴它):?或使用&#8209;&#x2011;

Note that this is the only unicode “character”which unifies the following characteristics:

请注意,这是唯一统一以下特征的Unicode“字符”

  • is pre-composed (you can make anything non-breaking by composition)
  • is non-breaking
  • is a hyphen or dash or similar
  • 是预先组合的(您可以通过组合制作任何不破坏的东西)
  • 是不间断的
  • 是连字符或破折号或类似的


The usage of the word joinerrepresented by &#8288;or &#x2060;allows for other hyphens. Results:


由或允许其他连字符表示 的单词 joiner的用法。结果:&#8288;&#x2060;

e‐⁠commerce(hyphen followed by word joiner)
e?⁠commerce(ASCII hyphen/minus followed by word joiner)
...and the precomposed one for reference:
e?commerce(non-breaking hyphen)

e-⁠commerce(连字符后跟单词 joiner)
e?⁠commerce(ASCII 连字符/减号后跟单词 joiner)
......以及预先组合的一个供参考:
e?commerce(不间断连字符)

http://jsfiddle.net/NR5Ch/58/  (this fiddle shows the effect of the word joiner)

http://jsfiddle.net/NR5Ch/58/  (这个fiddle展示了joiner这个词的效果)