2

我需要打断长词,例如长链接。我正在处理的布局是流体布局,因此没有提供固定宽度。取而代之的是,我需要我的文本块来适应任何容器的宽度并打破长字,以便它们适应任何宽度。

您在http://jsfiddle.net/cYDJd/1/有一个示例,其中您将看到一个长链接,该链接没有被 CSS 规则破坏,word-wrap: break-word;而图像在左侧浮动。只有当长链接位于图像下方时,才能word-wrap正常工作。

这里有 JSFiddle 代码的简化版本:

CSS:

.left {
    float: left;
}
.justified-block {
    text-align: justify;
    word-wrap:break-word;
}

HTML:

<a href="#" class="left"><img src="some-image.jpg" /></a>
<p class="justified-block">Some text with a very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong link.</p>

我将非常感谢您的友好建议。

4

1 回答 1

-1

像这样的东西?

我没有检查任何浏览器支持:/

http://jsfiddle.net/insan3/nrQFQ/2/

<style>
.block{
 width: 200px;
 display: block;
 border: 1px solid #DDD;
 display: table;
}

.block a{
 text-transform: uppercase;
}
.s1x{ font-size: 10px;}
.s2x{ font-size: 14px;}
.s3x{ font-size: 16px;}

.word-break{
 word-wrap: break-word;
 word-break: break-all;
 }
 </style>

<span class="block">
<p class="word-break"><a class="s1x" href="#">&bull;Current Lipsum Content Link Here it &bull;</a><a class="s3x" href="#">Current Lipsum Content Link Here it Current&bull;</a><a class="s1x" href="#"> Lipsum Content Link Here it Current Lipsum Content Link Here&bull;</a> <a class="s3x" href="#">it Current Lipsum Content Link Here it Current Lipsum Content Link Here it&bull;</a></p>

于 2013-10-05T03:28:40.780 回答