3

I'm trying to put ellipsis for text overflow:

parent:

.grid-row {
  display: flex;
}

child:

.grid-cell {
  display: flex;
  flex-grow: 3;
  flex-basis: 0;
  align-items: center;
  padding: 10px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.grid-cell:first-child {
  flex-grow: 1;
  justify-content: center;
}

And, well the overflow is hidden, but without any ellipsis.

kukkuz
  • 41,512
  • 6
  • 59
  • 95
Chen
  • 2,958
  • 5
  • 26
  • 45

3 Answers3

2

For text overflow to work you need a set width - set a width to your grid-row.

Also remove the display: flex from the grid-cell - see demo below:

.grid-row {
  display: flex;
  width: 250px;
}
.grid-cell {
  /*display: flex;*/
  flex-grow: 3;
  flex-basis: 0;
  /*align-items: center;*/
  padding: 10px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.grid-cell:first-child {
  flex-grow: 1;
  justify-content: center;
}
<div class="grid-row">
  <div class="grid-cell">insert text here</div>
  <div class="grid-cell">some text</div>
  <div class="grid-cell">some more text here</div>
</div>
kukkuz
  • 41,512
  • 6
  • 59
  • 95
  • 3
    In the question he needed the cell to be display: flex, asking to remove it makes the answer irrelevant. – Cesar Jul 28 '19 at 09:07
0
.grid-cell {
  display: flex;
  flex-grow: 3;
  flex-basis: 0;
  align-items: center;
  padding: 10px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  word-wrap:normal;
  width: ###px;
}

You should set the width of .grid-cell

kyun
  • 9,710
  • 9
  • 31
  • 66
0

Add this to your .grid-cell:

max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

Works like a charm.