【问题标题】:Wrap table cell with long word用长字包裹表格单元格
【发布时间】:2017-04-12 08:58:31
【问题描述】:

我试着按照这里的解释: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/

【问题讨论】:

标签: html css


【解决方案1】:

updated link

CSS代码:

table {
    width: 100%;
}
td {
    text-align: right;
    white-space: nowrap;
}
td div {
    white-space: normal;
    word-break: break-all;
    display: block;
}

【讨论】:

  • 非常感谢!这个简单的解决方案解决了一个痛苦的问题。
【解决方案2】:

选项 1.将 table-layout:fixed 添加到原始代码中的表中,以使 word-wrapcss 起作用。 https://jsfiddle.net/mpsingh2003/jfmqgh20/12/

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

【讨论】:

    【解决方案3】:

    您需要为表格单元格指定最小和最大宽度,而不是表头。

    .my-list {
        max-width: 100%;
    }
    
    th {
    }
    
    td {
        max-width: 300px;
        min-width: 150px;
        word-wrap: break-word;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-06-23
      • 1970-01-01
      • 1970-01-01
      • 2021-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      相关资源
      最近更新 更多