文本省略号不显示在flexbox项目上

cel*_*ade 5 html css css3 flexbox

我已经text-overflow: ellipsis在chrome和firefox上进行了测试,两者都缩短了文本,但它'...'最终没有显示出来.这有什么问题?

我已经使用其他解决方案,我发现这里如尝试min-width,max-width,flex: 0 1 auto,等等.但他们都不是工作.省略号没有出现.

这是我的代码:

ul {
  display: flex;
  height: 40px;
  margin: 0;
  padding: 0;
  width: 100%;
  list-style: none;
}
ul li {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 4px;
  border-bottom: 1px solid #eee;
}
ul li:first-child {
  width: 55px;
  flex-shrink: 0;
}
ul li:first-child input {
  width: 100%;
}
ul li:last-child {
  width: 48px;
  flex-shrink: 0;
}
ul li:nth-child(2) {
  flex: 0 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0px;
}
ul li:nth-child(3) {
  width: 75px;
  flex-shrink: 0;
}
Run Code Online (Sandbox Code Playgroud)

这是一个演示问题的小提琴:https://jsfiddle.net/dpbejpou/1/

注意:我已经尝试过使用其他解决方案,就像我说的那样,例如在此链接上找到的min-width,max-width(您可以在我的代码中看到),但代码stil不起作用.

Mic*_*l_B 1

为了text-overflow: ellipsis工作,您必须定义宽度。你有flex-basis: auto,但这还不够。

此外,text-overflow: ellipsis仅适用于块级元素。

弹性项目被认为是块化的,并且省略号将起作用。但是,您还应用于display: flex弹性项目,这打破了属性的块级规则display

尝试以下调整:

ul {
  display: flex;
  height: 40px;
  margin: 0;
  padding: 0;
  width: 100%;
  list-style: none;
}
ul li {
  /* display: flex;           <-- remove */
  /* align-items: center;     <-- will no longer work */
  height: 100%;
  padding: 0 4px;
  border-bottom: 1px solid #eee;
}
ul li:first-child {
  width: 55px;
  flex-shrink: 0;
}
ul li:first-child input {
  width: 100%;
}
ul li:last-child {
  width: 48px;
  flex-shrink: 0;
}
ul li:nth-child(2) {
  flex: 0 1 100px;              /* adjusted; 100px for demo only */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0px;
}
ul li:nth-child(3) {
  width: 75px;
  flex-shrink: 0;
}
Run Code Online (Sandbox Code Playgroud)
<ul>
  <li><input type="number" value="1"></li>
  <li>A very long text description goes here</li>
  <li>$99.90</li>
  <li>Del</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

修订版小提琴

要使文本垂直居中,您可以在非省略号元素上使用弹性布局,就像以前一样。要将省略号文本垂直居中,请尝试另一种方法

参考: