Bootstrap 使用 flexbox 时文本不会被截断

Bootstrap text does not truncate when using flexbox

我正在使用 flexbox 制作 Bootstrap 卡片,但无法进行文本截断。卡片文本按预期换行,但是,当没有足够的 space 时,卡片标题不会被截断,而是将内容推到卡片之外 (see screenshot)。

谁能解释为什么会这样?

<div class="container-fluid">
  <div class="row">
    <div class="col">
      <div class="card d-flex flex-row">
        <a href="#">[Image]</a>
        <div class="card-body d-flex align-items-center">
          <div class="flex-grow-1">
            <a href="#"><h5 class="card-title text-truncate">Lorem ipsum dolor sit amet, consetetur sadipscing elitr</h5></a>
            <div class="card-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam</div>
          </div>
          <small class="align-self-baseline text-nowrap">Lorem ipsum</small>
          <div>[Icon]</div>
        </div>
      </div>
    </div>
  </div>
</div>

See example on jsfiddle

在 flex-grow-1 中添加 flex-body div:

<div class="container-fluid">
  <div class="row">
    <div class="col">
      <div class="card d-flex flex-row">
        <a href="#">[Image]</a>
        <div class="card-body d-flex align-items-center">
          <div class="flex-grow-1">
           <div class="flex-body">
             <a href="#"><h5 class="card-title text-truncate">Lorem ipsum dolor sit amet, consetetur sadipscing elitr</h5></a>
             <div class="card-text">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam</div>
          </div>
          <small class="align-self-baseline text-nowrap">Lorem ipsum</small>
          <div>[Icon]</div>
        </div>
       </div>
      </div>
    </div>
  </div>
</div>

老实说,我不知道这是错误还是特性,但似乎flexbox and text truncation don't play well together

Without this (min-width), the flex child containing the other text elements won't narrow past the "implied width" of those text elements.

在您的特定情况下,我将 min-width: 0 设置为 .card-body.flex-grow-1 类。

jsfiddle