CSS:将自动换行符用于浮动图像的流体宽度文本

时间:2013-08-22 19:17:03

标签: css css-float word-wrap fluid-layout text-justify

我需要打破长话,例如长链接。我正在处理的布局是流体布局,因此没有提供固定宽度。而不是那样,我需要将我的文本块调整到任何容器的宽度,然后将长单词打破,以便它们适合任何宽度。

您在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>

我非常感谢你的善意。

1 个答案:

答案 0 :(得分:-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>