省略号不起作用(flexbox)

时间:2017-08-23 15:52:50

标签: html css css3 flexbox ellipsis

我试图将省略号用于文本溢出:

父:

.grid-row {
  display: flex;
}

子:

.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;
}

而且,overflowhidden,但没有任何省略号。

3 个答案:

答案 0 :(得分:1)

要让文字溢出正常工作,您需要一套width - 将width设置为grid-row

同时从display: flex中删除grid-cell - 请参阅下面的演示:



.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>
&#13;
&#13;
&#13;

答案 1 :(得分: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;
}

您应该设置width

.grid-cell

答案 2 :(得分:0)

将此添加到.grid-cell:

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

像魅力一样。