html / css中的“硬”单词分解/分裂

时间:2010-08-24 07:49:08

标签: css html line-breaks

如何在html div中显示长字/网址时,如何在某个点分割长字?

应该是这样的:

thisisareallylongwordt 
hatneedstobebroken her
e or something like th
at.

3 个答案:

答案 0 :(得分:5)

如果您希望单词在div的边缘处断开而不是溢出,请使用

div {word-wrap:break-word}

答案 1 :(得分:0)

您需要手动插入<br>代码:

thisisareallylongwordt<br>
hatneedstobebroken her<br>
e or something like  th<br>
at

没有像人们想要的那样,没有CSS解决方案。

编辑:正如Raoul建议的那样,软连字符&shy;也能正常工作。不知道自己存在。

答案 2 :(得分:0)

当div的大小发生变化时,你想要一个静态的自动换行或更动态的东西吗?如果你想要后者那么你可能想要使用javascript。 jQuery库有一个自动换行插件:

http://plugins.jquery.com/project/wordWrap