English 中文(简体)
html年中国文文本分离后,防止在外空中断
原标题:Preventing line breaks in space separated Chinese text in html
  • 时间:2012-05-13 14:13:36
  •  标签:
  • html
  • css

I have some text in Chinese which has been separated with white space for the purpose of learners. E.g. 我 喜欢 学 中文.

I would like to present this text in HTML, without introducing line breaks within the words. I would also like it to be possible for the text to break between words. How can I do that?

问题回答

http://www.fileformat.info/unicode/char/2060/index.htm Uni Wordcode Joiners (U +60, RUS Code ⁠),用于连接不应在线路上打碎的特性。

HTML

<span>我 喜&#8288;欢 学 中&#8288;文</span>

This works, but is not very semantical.

以下各点比较好,因为它没有改变实际案文(复制/印刷版是好的),而且你可以使用特别安全局和其他方法(超文本标题、 Java本)格式,使之具有互动性:

span.chineseWord {
  white-space: nowrap;
  padding: 0px 5px;
}
span.chineseWord:hover {
  background-color: yellow;
}
<span class="chineseWord">我</span>
<span class="chineseWord">喜欢</span>
<span class="chineseWord">学</span>
<span class="chineseWord">中文</span>

Using a no-break space (U+00A0) instead a normal space you can mostly prevent a line break in a specific location where you wish to have some space. (I wrote “mostly”, because browsers do not quite consistently implement no-break space semantics.) But doing so in Chinese text will just make browsers break lines between Chinese characters in positions where no space is used—on modern browsers.

Modern browsers generally implement part of Unicode line breaking rules, which define that line breaks are generally allowed between Chinese characters, unless prevented by specific rules.

如果希望在案文的某一部分内防止all细线断裂,那么最有效的方法是打上标签<nobr></nobr>。 如果你将符合标准,以某些功能损失的成本计算,使该部分成为一种要素,如<代码>span,并分配<代码>white-space: nowrap<>/code>至CSS。 如果您愿意允许在这种部分的具体职位上打分界线,则使用(冒犯)标签<wbr>或U+200B特性(例如,可通过写作&#x200b;)。

More info: http://www.cs.tut.fi/~jkorpela/html/nobr.html

在问询员额之后的几年,<代码> 字节:不间断/<>代码>最后由15和44年获得支持。 这将是被占领土希望的:

.text {
  word-break: keep-all;
  
  resize: both;
  overflow: hidden;
  border: 1px solid #aaa;
}
<div class="text">我 家 的 后面 有 一个 很大 的 园 , 相传 叫作 百草园 。 现在 是 早已 并 屋子 一起 卖 给 朱文公 的 子孙 了 , 连 那 最 末次 的 相见 也 已经 隔 了 七八年 , 其中 似乎 确凿 只有 一些 野草 ; 但 那时 却是 我的 乐园 。</div>




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签