Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 truncate long text inside rows of a table in a responsive way

I'm using bootstrap 3 tables, when i put large text in the table it gets wrapped on several lines, but i want it to be truncated with three dots at the end in a responsive way without messing up the layout of the table (i found some solutions but with unpleasant effects).

Is that possible ? how ?

PS: any solution is welcome, but i would like it to be just HTML/CSS if it's possible.

like image 329
Xsmael Avatar asked May 02 '14 15:05

Xsmael


2 Answers

You need to use table-layout:fixed in order for CSS ellipsis to work on the table cells.

.table {   table-layout:fixed; }  .table td {   white-space: nowrap;   overflow: hidden;   text-overflow: ellipsis; } 

demo: http://bootply.com/9njmoY2CmS

like image 71
Zim Avatar answered Oct 06 '22 06:10

Zim


I did it this way (you need to add a class text to <td> and put the text between a <span>:

HTML

<td class="text"><span>looooooong teeeeeeeeext</span></td>

SASS

.table td.text {     max-width: 177px;     span {         white-space: nowrap;         overflow: hidden;         text-overflow: ellipsis;         display: inline-block;         max-width: 100%;     } } 

CSS equivalent

.table td.text {     max-width: 177px; } .table td.text span {     white-space: nowrap;     overflow: hidden;     text-overflow: ellipsis;     display: inline-block;     max-width: 100%; } 

And it will still be mobile responsive (forget it with layout=fixed) and will keep the original behaviour.

PS: Of course 177px is a custom size (put whatever you need).

like image 33
Luciano Fantuzzi Avatar answered Oct 06 '22 05:10

Luciano Fantuzzi