用连字符

时间:2017-03-09 02:52:21

标签: css css-hyphens

我想在第一行末尾用连字符打破长词。

预期:

BERUFSBILDUNGSZENT-
RUM

得到了这个:

BERUFSBILDUNGSZENT
RUM

这是我的html和css:

<div class="content">BERUFSBILDUNGSZENTRUM</div>

.content {
  max-height: 80px;
  width: 200px;
  overflow-x: hidden;
  word-wrap: break-word;
  padding: 10px;
  -webkit-hyphens: auto;
  -moz-hyphens: auto;
  -ms-hyphens: auto;
  hyphens: auto;
  font-weight: bold;
  font-size: 16px;
  border: solid 1px #000;
}

您可以查看我的JSFiddle

2 个答案:

答案 0 :(得分:4)

Chrome显然没有连字符(至少在Windows上)。使用其他浏览器或平台可能会更好。如果您事先知道要打破的位置,可以使用&shy;(软连字符)。否则,至少在Windows上的Chrome中,当CSS打破一个长词时,无法获得连字符,除非它在输入中开始。

.content {
  max-height: 80px;
  width: 200px;
  overflow-x: hidden;
  word-wrap: break-word;
  padding: 10px;
  font-weight: bold;
  font-size: 16px;
  border: solid 1px #000;
}
Using soft hyphen:
<div class="content">BERUFSBILDUNGSZEN&shy;TRUM</div>    

Using automatic hyphenation (doesn't work in Chrome)
<div class="content" lang="de" style="hyphens: auto; ">BERUFSBILDUNGSZENTRUM</div>

Soft hyphen not displayed if it doesn't break there
<div class="content" style="width: 400px; ">BERUFSBILDUNGSZEN&shy;TRUM</div>

另见this answer

答案 1 :(得分:-1)

lang="de"属性添加到HTML标记中,因为浏览器正在使用由该语言标记决定的算法来决定这一点。

相关问题