Flexbox容器中的省略号

时间:2014-10-20 12:28:32

标签: css firefox

自从Firefox Nightly(35.0a1)发布最新版本(?)以来,text-overflow: ellipsisflex-direction: row的Flexbox容器中遇到问题,每列的宽度为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>
&#13;
&#13;
&#13;

在Nightly中,文本将泄漏到其容器外部,而不是在末尾附加...。在Chrome和Firefox Stable中,它可以正常运行。

1 个答案:

答案 0 :(得分:82)

这最终被追溯到最近Firefox Nightly的变化。简而言之,在min-width: 0选择器上设置.column会使其按预期工作。

可以找到更全面的答案here。值得注意的是:

  

&#34;基本上:flex项目将拒绝收缩到其最小固有宽度以下,除非您明确指定&#34; min-width&#34;或&#34;宽度&#34;或&#34; max-width&#34;在他们身上。&#34;

工作解决方案:

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