I need to break long words as for example long links. The layout I am working on is a fluid-layout, so no fixed width is provided. Instead of that, I need my text block to adjust to any container's width and get long words broken so that they justify to any width.
我需要打破长话,例如长链接。我正在处理的布局是流体布局,因此没有提供固定宽度。而不是那样,我需要我的文本块来调整任何容器的宽度,并让长字被打破,以便它们适合任何宽度。
You have an example at http://jsfiddle.net/cYDJd/1/ in which you will see a long link which is not being broken by CSS rule word-wrap: break-word;
while image is floating at the left. Only when the long link is below the image, word-wrap
works fine.
你在http://jsfiddle.net/cYDJd/1/有一个例子,你会看到一个很长的链接,它没有被CSS规则word-wrap打破:break-word;而图像浮动在左侧。只有当长链接在图像下方时,自动换行才能正常工作。
Here you have the reduced version of JSFiddle's code:
这里有JSFiddle代码的简化版本:
CSS:
CSS:
.left {
float: left;
}
.justified-block {
text-align: justify;
word-wrap:break-word;
}
HTML:
HTML:
<a href="#" class="left"><img src="some-image.jpg" /></a>
<p class="justified-block">Some text with a very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong link.</p>
I will appreciate very much your kind suggestions.
我非常感谢你的善意建议。
1 个解决方案
#1
-1
Something like this?
像这样的东西?
I didn´t check any browser support :/
我没有检查任何浏览器支持:/
http://jsfiddle.net/insan3/nrQFQ/2/
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="#">•Current Lipsum Content Link Here it •</a><a class="s3x" href="#">Current Lipsum Content Link Here it Current•</a><a class="s1x" href="#"> Lipsum Content Link Here it Current Lipsum Content Link Here•</a> <a class="s3x" href="#">it Current Lipsum Content Link Here it Current Lipsum Content Link Here it•</a></p>
#1
-1
Something like this?
像这样的东西?
I didn´t check any browser support :/
我没有检查任何浏览器支持:/
http://jsfiddle.net/insan3/nrQFQ/2/
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="#">•Current Lipsum Content Link Here it •</a><a class="s3x" href="#">Current Lipsum Content Link Here it Current•</a><a class="s1x" href="#"> Lipsum Content Link Here it Current Lipsum Content Link Here•</a> <a class="s3x" href="#">it Current Lipsum Content Link Here it Current Lipsum Content Link Here it•</a></p>