Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

What are some of the common ways to left align some text and right align some other text within a div container in bootstrap?

(有什么常见的方法可以左对齐一些文本并在引导程序中对div容器中的其他文本进行右对齐?)

eg

(例如)

Total cost                   $42

Above total cost should be left aligned text and $42 is right aligned text

(以上总费用应为左对齐文本,42美元为右对齐文本)

  ask by user462455 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
677 views
Welcome To Ask or Share your Answers For Others

1 Answer

2018 Update...

(2018年更新......)

Bootstrap 4.1+

(Bootstrap 4.1+)

  • pull-right is now float-right

    (pull-right现在是float-right)

  • text-right is the same as 3.x, and works for inline elements

    (text-right与3.x相同,适用于内联元素)

  • both float-* and text-* are responsive for different alignment at different widths (ie: float-sm-right )

    (float-*text-*响应不同宽度的不同对齐(即: float-sm-right ))

The flexbox utils (eg: justify-content-between ) can also be used for alignment:

(flexbox utils(例如: justify-content-between )也可用于对齐:)

<div class="d-flex justify-content-between">
      <div>
         left
      </div>
      <div>
         right
      </div>
 </div>

or, auto-margins (eg: ml-auto ) in any flexbox container (row,navbar,card,d-flex,etc...)

(或者,任何弹性箱容器中的自动边距(例如: ml-auto )(行,导航栏,卡片,d-flex等...))

<div class="d-flex">
      <div>
         left
      </div>
      <div class="ml-auto">
         right
      </div>
 </div>

Bootstrap 4 Align Demo

(Bootstrap 4对齐演示)
Bootstrap 4 Right Align Examples (float, flexbox, text-right, etc...)

(Bootstrap 4右对齐示例 (float,flexbox,text-right等...))


Bootstrap 3

(Bootstrap 3)

Use the pull-right class..

(使用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>

Bootstrap 3 Demo

(Bootstrap 3演示)

You can also use the text-right class like this:

(你也可以使用像这样的text-right类:)

  <div class="row">
    <div class="col-md-6">Total cost</div>
    <div class="col-md-6 text-right">$42</div>
  </div>

Bootstrap 3 Demo 2

(Bootstrap 3演示2)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...