6

我的客户希望在他的网站上没有任何文字被破坏。例子:

The dog went for a walk and ran to-
wards the car.

应该

The dog went for a walk and ran 
towards the car.

该问题仅出现在 Safari 中。有谁知道解决这个问题的 CSS 属性?

4

2 回答 2

11

添加 CSS 规则

* { -webkit-hyphens: none; }

Safari 对单词进行连字的唯一情况(根据描述会发生这种情况)是显式的连字提示,如在 中to­wards,或通过自动连字通过-webkit-hyphens: auto. Safari 被描述为支持自动断字,但这似乎不适用于 Windows 版本(5.1.7)。无论如何,上述规则对任何一种方式都有帮助。

另一方面,最好防止不希望的断字。

于 2012-12-20T17:49:50.213 回答
1

我在 chrome 和 safari 中尝试了这个,它似乎按预期工作:

white-space:pre-wrap;

例子:

#noBroeknWords
{
 white-space:pre-wrap;
}

<div style="width:400px">
    <span id='noBroeknWords'>
    LongWord, ShouldNotBeBroken ShouldNotBeBroken ShouldNotBeBroken ShouldNotBeBroken ShouldNotBeBroken ShouldNotBeBrokenShouldNotBeBroken  ShouldNotBeBrokenShouldNotBeBroken ShouldNotBeBrokenShouldNotBeBroken.
    </span>
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</div>

这是jsFiddle

于 2012-12-20T14:28:03.533 回答