Flex 中文本截断

Tags
css
Created
May 12, 2016 12:42 PM

<div class="flex-parent">

<div class="flex-child">

<h2>Text to truncate here.</h2>

</div>

<div class="flex-child">

Other stuff.

</div>

</div>

.flex-child > h2 {

white-space: nowrap;

overflow: hidden;

text-overflow: ellipsis;

}

When I first ran into this problem, I found the solution via a Pen by AJ Foster. He writes:

According to a draft spec, the above text should not fully collapse when the flex container is resized down. Because .subtitle has a width of 100%, the min-width: auto calculation that flexbox makes says that its container should be larger than we want.

I found this behavior consistent across Chrome, Opera, and Firefox. Safari was shrinking/truncating even without the min-width (against spec, I think).

另外 flex-child 使用overflow: hidden; 也行

SuperMade with Super