break long word around floating image

半世苍凉 提交于 2019-12-05 08:19:12

Insert ­ soft-breaks in the long word. There are various PHP libraries that can do that for you, based on dictionaries.

Could use PHP to prep the text block, shortening long words with something like ...

    $words = explode(' ',$str);
    foreach ($words as $word) {
        if (strlen($word) > 20) {
            $part1 = substr($word,0,20);
            $part2 = substr($word,21);
            $newwords[] = $part1 .' '. $part2;
        } else {
            $newwords[] = $word;
        }
    }
    $newstr = implode(' ',$newwords);

You can sprinkle <wbr> tags in the long word. The browser will use them to break whenever it is needs to. If not needed, it won't break there. Here is your jsfiddle example fixed: http://jsfiddle.net/vAdPy/

Note that the closer are the <wbr> tags to each other, the better results you get as the browser has more options to find a suitable place to break the long word.

Here is a PHP script to sprinkle <wbr> tags into the text.

<?php
    $word = 'thisisaverylongword';
    $wbr_word = preg_replace('/(..)/', '\\1<wbr>', $word);

    // $wbr_word is now "th<wbr>is<wbr>is<wbr>av<wbr>er<wbr>yl<wbr>on<wbr>gw<wbr>or<wbr>d"
?>

This inserts a <wbr> tag after every two characters (note the two dots in the regex) of the long-text. You can alter the number of dots in the regex to control how far apart two consecutive <wbr> tags should be.

Tehuel Diseño

For me this solution was the best (with long words and float elements):

    -ms-word-break: break-all;
     word-break: break-all;
     word-break: break-word;
     -webkit-hyphens: auto;
     -moz-hyphens: auto;
     hyphens: auto;

http://blog.kenneth.io/blog/2012/03/04/word-wrapping-hypernation-using-css/

There are only problems in Chrome.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!