2

I try to follow the explication here : How to wrap table cell at a maximum width in full width table

But I can't make something works to wrap my "xxxxxxxxxxxxx" line.

<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/

Community
  • 1
  • 1
Bouffe
  • 770
  • 13
  • 37

3 Answers3

12

updated link

Css Code:

table {
    width: 100%;
}
td {
    text-align: right;
    white-space: nowrap;
}
td div {
    white-space: normal;
    word-break: break-all;
    display: block;
}
SVK
  • 2,107
  • 2
  • 20
  • 41
1

you needed to give the table cell a min and max width not the table head.

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

th {
}

td {
    max-width: 300px;
    min-width: 150px;
    word-wrap: break-word;
}
Loïc Faure-Lacroix
  • 13,220
  • 6
  • 67
  • 99
Sharper
  • 327
  • 3
  • 17
0

Option 1.Add table-layout:fixed to table in your original code for word-wrapcss to work. https://jsfiddle.net/mpsingh2003/jfmqgh20/12/

Option 2. Use word-break: break-word; css property. And also set min-width of td.
Updated JS Fiddle https://jsfiddle.net/mpsingh2003/jfmqgh20/9/

manpreet
  • 636
  • 5
  • 20