【问题标题】:CSS: apply word-wrap break-word to fluid width text with floating imageCSS:将自动换行断词应用于具有浮动图像的流体宽度文本
【发布时间】:2013-10-05 11:28:40
【问题描述】:

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

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

非常感谢您的好意建议。

【问题讨论】:

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


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 2012-04-20
    • 2010-10-11
    • 1970-01-01
    • 2016-10-12
    • 1970-01-01
    相关资源
    最近更新 更多