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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25888822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:43:20  来源:igfitidea点击:

css - display: table-cell and fixed width

htmlcss

提问by Levi

I have some divswith display: table-cellstyle and I would like to set fixed width on the divsand to truncate the text inside if it doesn't fit.

我有一些divsdisplay: table-cell风格,我想设置的固定宽度divs,并截断内,如果它不适合文本。

HTML

HTML

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

CSS

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?

是否可以?

采纳答案by Alex Char

You can set max-widthinstead:

您可以max-width改为设置:

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

fiddle

小提琴