Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap table cell with long word

Tags:

html

css

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/

like image 510
Bouffe Avatar asked Nov 16 '25 05:11

Bouffe


2 Answers

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;
}
like image 173
SVK Avatar answered Nov 18 '25 20:11

SVK


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;
}
like image 41
Sharper Avatar answered Nov 18 '25 19:11

Sharper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!