20

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?

3
  • You can't set a fixed width on table-cell elements Commented Sep 17, 2014 at 11:03
  • @Guy I think you are the only one seeing actuall cells here.. since Levi is using div's Commented Sep 17, 2014 at 11:04
  • @Azrael a div can be a table-cell element by changing its display property to display: table-cell; Commented Jun 8, 2018 at 2:13

1 Answer 1

16

You can set max-width instead:

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

fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

any way we can set the width in percentages?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.