如何将break-all限制为只有长词? [英] How to limit break-all to only long words?

查看:26
本文介绍了如何将break-all限制为只有长词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在基于引导程序的模板中的所有 col 中打破很长的单词(还有一些很长的 uuid),但是当我对所有列使用以下样式时,它会破坏所有内容(检查错误在示例中打断)即使是正常的地方换行也能完美地工作(检查示例中的预期打断).

I am trying to break very long words(some long uuid as well) in all col in bootstrap based template, but when I use the below style for all columns, it breaks everything(check bad breaking in example) even the places were normal wrapping at words worked perfectly(check expected breaking in example).

有没有一种方法可以在任何可能的情况下使用正常的中断,并且只有当它失败时才恢复到 break-all ?如果对性能没有太大影响,也欢迎使用 Javascript 技巧.

Is there a way I can use normal breaking wherever possible and revert to break-all only when it fails to do the trick? Javascript tricks are also welcome if that doesn't affect performance much.

如果文本没有任何空间并溢出,我希望正常中断对空格操作的普通文本和 break-all 起作用.我想知道这是否可能!

I want normal breaking to work for space operated normal text and break-all to work if the text doesn't have any space and overflows. I wonder if this is even possible!

div {
  white-space: -moz-pre-wrap;
  /* Mozilla */
  white-space: -hp-pre-wrap;
  /* HP printers */
  white-space: -o-pre-wrap;
  /* Opera 7 */
  white-space: -pre-wrap;
  /* Opera 4-6 */
  white-space: pre-wrap;
  /* CSS 2.1 */
  white-space: pre-line;
  /* CSS 3 (and 2.1 as well, actually) */
  word-wrap: break-word;
  /* IE */
  word-break: break-all;
}
.fifty {
  width: 200px;
  float: left;
  border: 10px solid #e6e6e6;
  margin: 1px;
  font-size: 14px;
  font-family: Verdana;
}
h6 {
  clear: both;
  margin:0;
}

<div class="fifty">aquickwhitefoxjumpsoverafrozendog</div>
<div class="fifty">A Quick White Fox Jumps Over A Frozen Dog</div>

<h6>Bad breaking at all places</h6>
<div class="fifty">StackOverflow is a privately held website, the flagship site of the StackExchangeNetwork, created in 2008 by Jeff-Atwood and Joel-Spolsky</div>

<h6>Expected breaking</h6>
<article class="fifty">StackOverflow is a privately held website, the flagship site of the StackExchangeNetwork, created in 2008 by Jeff-Atwood and Joel-Spolsky</article>

推荐答案

div {

  / These are technically the same, but use both /
  overflow-wrap: break-word;
  word-wrap: break-word;

  -ms-word-break: break-all;
  / This is the dangerous one in WebKit, as it breaks things wherever /
  word-break: break-all;
  / Instead use this non-standard one: /
  word-break: break-word;

  / Adds a hyphen where the word breaks, if supported (No Blink) /
  -ms-hyphens: auto;
  -moz-hyphens: auto;
  -webkit-hyphens: auto;
  hyphens: auto;

}
.fifty {
  width: 200px;
  float: left;
  border: 10px solid #e6e6e6;
  margin: 1px;
  font-size: 14px;
  font-family: Verdana;
}
h6 {
  clear: both;
  margin:0;
}

<div class="fifty">aquickwhitefoxjumpsoverafrozendog</div>
<div class="fifty">A Quick White Fox Jumps Over A Frozen Dog</div>

<h6>Bad breaking at all places</h6>
<div class="fifty">StackOverflow is a privately held website, the flagship site of the StackExchangeNetwork, created in 2008 by Jeff-Atwood and Joel-Spolsky</div>

<h6>Expected breaking</h6>
<article class="fifty">StackOverflow is a privately held website, the flagship site of the StackExchangeNetwork, created in 2008 by Jeff-Atwood and Joel-Spolsky</article>

这篇关于如何将break-all限制为只有长词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆