将底部与Bootstrap 4对齐

时间:2019-02-08 17:55:20

标签: twitter-bootstrap bootstrap-4 vertical-alignment

在Bootstrap 4中对齐底部似乎不适用于我。

下面是我的代码。我希望文本显示为与底部的行对齐。我不能使用边距/填充,因为有时,此文本将是多行。

如何垂直对齐底部?

<div style="height:55px !important;">
  <span class="align-bottom">
    This text should align to bottom, closer to the line
  </span>
</div>
<div class="border-top">
    Other content below the line
</div>

JSFiddle:https://jsfiddle.net/wqeah67v/

2 个答案:

答案 0 :(得分:2)

explained here一样,display:block内的底部对齐也不起作用。

使用显示表格单元格或flexbox对齐底部。

<div style="height:55px !important;" class="align-bottom d-table-cell">
  <span>
    This text should align to bottom, closer to the line
  </span>
</div>

或者

<div style="height:55px !important;" class="d-flex">
  <span class="align-self-end">
    This text should align to bottom, closer to the line
  </span>
</div>
<div class="border-top">
    Other content
</div>

演示:https://www.codeply.com/go/SOtL0ovFZR

答案 1 :(得分:1)

您可以按如下方式在底部对齐文本:

<div style="height:55px !important; position: relative;">
  <span class="align-bottom" style="position: absolute;bottom:0;">
    This text should align to bottom, closer to the line
  </span>
</div>
<div class="border-top">
    Other content
</div>

有效的jsfiddle链接为:https://jsfiddle.net/ez7rbk1u/