一尘不染

flexbox容器中的省略号

css

自从Firefox Nightly(35.0a1)的最新(?)版本以来,我一直在使用text-overflow: ellipsis的flexbox容器内部遇到问题flex-direction: row,每个列的宽度为50%。

演示:

.container {

  width: 300px;

  background: red;

}



.row {

  display: flex;

  flex-direction: row;

  flex-wrap: wrap;

}



.column {

  flex-basis: 50%;

}



.column p {

  background: gold;



  /* Will not work in Firefox Nightly 35.0a1 */

  text-overflow: ellipsis;

  overflow: hidden;

  white-space: nowrap;

}


<div class="container">

  <div class="row">

    <div class="column">

      <p>Captain's Log, Stardate 9529.1: This is the final cruise of the starship Enterprise under my command. This ship and her history will shortly become the care of another crew. To them and their posterity will we commit our future. They will continue the voyages we have begun and journey to all the undiscovered countries boldly going where no man, where no one has gone before.</p>

    </div>

    <div class="column">

      <p>Captain's Log, Stardate 9529.1: This is the final cruise of the starship Enterprise under my command. This ship and her history will shortly become the care of another crew. To them and their posterity will we commit our future. They will continue the voyages we have begun and journey to all the undiscovered countries boldly going where no man, where no one has gone before.</p>

    </div>

  </div>

</div>

在“每晚”中,文本将泄漏到其容器外部,并且不会...在末尾附加。在Chrome和Firefox稳定版中,它可以按预期工作。


阅读 294

收藏
2020-05-16

共1个答案

一尘不染

最终可以追溯到Firefox Nightly中的最新更改。长话短说,选择器min-width:0上的设置.column将使其按预期工作。

在这里可以找到更全面的答案。注意:

“基本上:弹性项目将拒绝收缩到其最小固有宽度以下,除非您在其上明确指定“最小宽度”或“宽度”或“最大宽度”。

工作解决方案:

.container {

  width: 300px;

  background: red;

}



.row {

  display: flex;

  flex-direction: row;

  flex-wrap: wrap;

}



.column {

  /* This will make it work in Firefox >= 35.0a1 */

  min-width: 0;

  flex-basis: 50%;

}



.column p {

  background: gold;

  text-overflow: ellipsis;

  overflow: hidden;

  white-space: nowrap;

}


<div class="container">

  <div class="row">

    <div class="column">

      <p>Captain's Log, Stardate 9529.1: This is the final cruise of the starship Enterprise under my command. This ship and her history will shortly become the care of another crew. To them and their posterity will we commit our future. They will continue the voyages we have begun and journey to all the undiscovered countries boldly going where no man, where no one has gone before.</p>

    </div>

    <div class="column">

      <p>Captain's Log, Stardate 9529.1: This is the final cruise of the starship Enterprise under my command. This ship and her history will shortly become the care of another crew. To them and their posterity will we commit our future. They will continue the voyages we have begun and journey to all the undiscovered countries boldly going where no man, where no one has gone before.</p>

    </div>

  </div>

</div>
2020-05-16