Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table column text-overflow ellipsis ( width in % )

Tags:

html

css

I have this markup for mobile.

<table>
<tr>
<td style="width:60%">
<div class="ellipsis">
Test bla bla
</div>
</td>
<td style="width:40%">
</td>
</tr>

CSS

.ellipsis { 
width : 100%;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
word-break: break-all;
word-wrap: break-word;
}

The truncation doesn't work as desired, instead the column expands depending on content.

Table-Layout : fixed makes both the columns equal.

Any suggestions ? Thanks.

like image 456
Rakesh Avatar asked May 01 '26 22:05

Rakesh


1 Answers

Please use the following css to make css3 truncation work with tables

table {
   width: 200px; /*specify a width*/
   table-layout:fixed;
}

The property "table-layout:fixed" seems important to work text truncation for any block level elements inside a table.

like image 172
Hirak Avatar answered May 04 '26 10:05

Hirak



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!