Bootstrap の div コンテナー内で一部のテキストを左揃えにし、他の一部のテキストを右揃えにする一般的な方法は何ですか?
例えば
Total cost $42
上記の合計金額は左揃えのテキストで、$42 は右揃えのテキストです。
ベストアンサー1
2021 アップデート...
Bootstrap 5 (ベータ版)
flexbox div 内またはrow
...内で配置する場合
ml-auto
今でしょms-auto
mr-auto
今でしょme-auto
テキストの配置またはフロート用。
text-left
今でしょtext-start
text-right
今でしょtext-end
float-left
今でしょfloat-start
float-right
今でしょfloat-end
ブートストラップ4+
pull-right
今でしょfloat-right
text-right
3.xと同じで、インライン要素でも動作しますfloat-*
とtext-*
は両方とも応答性異なる幅で異なる配置の場合(例float-sm-right
:)
flexbox ユーティリティ (例: justify-content-between
) も配置に使用できます。
<div class="d-flex justify-content-between">
<div>
left
</div>
<div>
right
</div>
</div>
ml-auto
または、任意のフレックスボックス コンテナー (行、ナビゲーション バー、カード、d-flex など) 内の自動マージン (例: )
<div class="d-flex">
<div>
left
</div>
<div class="ml-auto">
right
</div>
</div>
Bootstrap 4 Align デモ
Bootstrap 4 右揃えの例(float、flexbox、text-right など)
ブートストラップ3
クラスを使用しますpull-right
。
<div class="container">
<div class="row">
<div class="col-md-6">Total cost</div>
<div class="col-md-6"><span class="pull-right">$42</span></div>
</div>
</div>
次のようにクラスを使用することもできますtext-right
:
<div class="row">
<div class="col-md-6">Total cost</div>
<div class="col-md-6 text-right">$42</div>
</div>