I have a table of divs using display: column; width: 100px;
The cells are using display: table-cell; white-space: nowrap; overflow: hidden;
because I always want the data to be on the same row and if it's too long it should be cut off.
Here is a jsfiddle.
<div class="table">
<div class="column1" style="display:table-column;width:50px;overflow:hidden;"></div>
<div class="column2" style="display:table-column;width:50px;overflow:hidden;"></div>
<div class="column3" style="display:table-column;width:200px;overflow:hidden;"></div>
<div class="column4" style="display:table-column;width:50px;overflow:hidden;"></div>
<div class="row">
<div class="cell"><span>a sdf</span></div>
<div class="cell"><span>as dlfk jas dofj </span></div>
<div class="cell"><span>as klödfjasdfj asöldfjk as</span></div>
<div class="cell"><span>a sdf</span></div>
</div>
<div class="row">
<div class="cell"><span>a sdf</span></div>
<div class="cell"><span>as dlfk jas dofj </span></div>
<div class="cell"><span>as klödfjasdfj asöldfjk </span></div>
<div class="cell"><span>a sdf</span></div>
</div>
<div class="row">
<div class="cell"><span>a sdf</span></div>
<div class="cell"><span>as dlfk jas dofj </span></div>
<div class="cell"><span>kludd as klödfjasdfj asöldfjkaskj fhalksfh alskdfhak dfhaslkfhasldfh asklh aslkdfh asklfh</span></div><!-- Add this to the cell: style="max-width:0px;"-->
<div class="cell"><span>a sdf</span></div>
</div>
<div class="row">
<div class="cell"><span>a sdf</span></div>
<div class="cell"><span>as dlfk jas dofj </span></div>
<div class="cell"><span>as klödfjasdfj asöldfjk </span></div>
<div class="cell"><span>a sdf</span></div>
</div>
<div>
.table{
display:table;
table-layout:fixed;
border:1px solid;
}
.row{
display:table-row;
}
.cell{
display:table-cell;
border-right:1px solid;
white-space:nowrap;
overflow:hidden;
}
.cell:last-of-type{
border:0;
}
.cell span{
text-overflow:ellipsis;
}
The table is acting like it should until the data is longer than 200px. I could solve this by setting max-width: 200px;
on the cell. However the width is a dynamic value from the server and I don't want to render this unnecessary data for every cell in the style-attribute.
Is it possible to write my columns in a way to solve this?
One more strange thing,
If I set max-width: 0px;
in a style attribute on the cell with very long data it renders as 200px! Can someone explain that?
I think this is what your asking, let me know if I'm wrong.
set the [max-width] to whatever you want then set [overflow:scroll]
//CSS BLOCK