How can I allow text to wrap inside a word if necessary?

后端 未结 8 989
清歌不尽
清歌不尽 2020-12-09 08:45

I am looking for the best solution to allow text to wrap in the middle of a word if necessary. By best, I mean most browser-compatible, and will favor word breaks before it

8条回答
  •  没有蜡笔的小新
    2020-12-09 09:44

    I found a similar answer here: http://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/

    A more robust browser support

    CSS only

    -ms-word-break: break-all;
    
         /* Be VERY careful with this, breaks normal words wh_erever */
         word-break: break-all;
    
         /* Non standard for webkit */
         word-break: break-word;
    
    -webkit-hyphens: auto;
       -moz-hyphens: auto;
            hyphens: auto;
    

    If your text is PHP generated you have a PHP function:

    wordwrap

    \n");
    
      echo $newtext;
    ?>
    

    Also, you can try PHP function explode if you have and know the delimiter. Display after with for loop (explode returns an array).

提交回复
热议问题