用长字包裹表格单元格

时间:2015-09-25 08:51:31

标签: html css

我尝试按照此处的说明进行操作:How to wrap table cell at a maximum width in full width table

但我无法创造出能够包装我的" xxxxxxxxxxxxx"线。

<table class="my-list table table-bordered table-hover">
    <tbody>
        <tr>
            <th>User id</th>
            <th>User name</th>
            <th>Type</th>
            <th>Id</th>
            <th>Ad content</th>
            <th>Created at</th>
        </tr>
        <tr>
            <td>66666</td>
            <td>John Smith</td>
            <td>type1</td>
            <td>99999</td>
            <td>
                <div>
                    Good content with words and real sentences.
                </div>
            </td>
            <td>2015-09-02</td>
        </tr>
        <tr>
            <td>777777</td>
            <td>Martin  Isabelle</td>
            <td>type2</td>
            <td>888888</td>
            <td>
                <div>
                    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                </div>
            </td>
            <td>2015-09-02</td>
        </tr>
    </tbody>
</table>

https://jsfiddle.net/jfmqgh20/2/

3 个答案:

答案 0 :(得分:9)

updated link

Css代码:

retriveInfoStep3

答案 1 :(得分:0)

选项1.在原始代码中将table-layout:fixed添加到word-wrap css的表格中。 https://jsfiddle.net/mpsingh2003/jfmqgh20/12/

选项2.使用word-break: break-word; css属性。并设置td的最小宽度。
更新了JS小提琴https://jsfiddle.net/mpsingh2003/jfmqgh20/9/

答案 2 :(得分:0)

你需要给表格单元格一个最小和最大宽度而不是表头。

.my-list {
    max-width: 100%;
}

th {
}

td {
    max-width: 300px;
    min-width: 150px;
    word-wrap: break-word;
}