且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CSS - 显示:表格单元格和固定宽度

更新时间:2022-10-30 23:01:56

您可以设置 max-width 代替:

 < div class =cellstyle =max-width:100px;>不适合100px< / div> 

小提琴


I have some divs with display: table-cell style and I would like to set fixed width on the divs and to truncate the text inside if it doesn't fit.

HTML

<div class="row">
    <div class="cell" style="width:100px;">Should not fit in 100px</div>
</div>

CSS

 .row {
     display: table-row;
}

.cell {
    display: table-cell;
    border: solid 1px #DADADA;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

FIDDLE DEMO

Is it possible?

You can set max-width instead:

<div class="cell" style="max-width:100px;">Should not fit in 100px</div>

fiddle