像aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa这样的文本超过了div的宽度(比如200px),如何被包装?

我是开放的任何一种解决方案,如CSS, jQuery等。


当前回答

试试这个

div { 显示:块; 显示:-webkit-box; 高度:20 px; Margin: 3px auto; 字体大小:14 px; 行高:1.4; -webkit-line-clamp: 1; -webkit-box-orient:垂直; 溢出:隐藏; 文本溢出:省略; }

属性text-overflow:省略号add…而线夹则显示线数。

其他回答

在HTML正文中尝试:

<table>
    <tr>
        <td>
            <div style="word-wrap: break-word; width: 800px">
                Hello world, how are you? More text here to see if it wraps after a long while of writing and it does on Firefox but I have not tested it on Chrome yet. It also works wonders if you have a medium to long paragraph. Just avoid writing in the CSS file that the words have to break-all, that's a small tip.
            </div>
        </td>
    </tr>
</table>

在CSS正文尝试:

background-size: auto;

table-layout: fixed;

你可以使用这个CSS

p {
  width: min-content;
  min-width: 100%;
}

跨浏览器

.wrap
{
    white-space: pre-wrap; /* css-3 */    
    white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
    white-space: -pre-wrap; /* Opera 4-6 */    
    white-space: -o-pre-wrap; /* Opera 7 */    
    word-wrap: break-word; /* Internet Explorer 5.5+ */
}

一个服务器端解决方案,对我来说是:$message = wordwrap($message, 50, "<br>", true);其中$message是一个字符串变量,包含要拆分的单词/字符。50是任何给定段的最大长度,“<br>”是你想要每(50)个字符插入的文本。

使用word-wrap:break-word属性以及所需的宽度。主要是, 宽度以像素为单位,而不是百分比。

width: 200px;
word-wrap: break-word;