Twitter bootstrap浮动div权利

Jus*_*tin 141 html css twitter-bootstrap

bootstrap将div浮动到右边的正确方法是什么?我认为这pull-right是推荐的方式,但它不起作用.

@import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');
 .container {
    margin-top: 10px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
    <div class="row-fluid">
        <div class="span6">
            <p>Text left</p>
        </div>
        <div class="span6 pull-right">
            <p>text right</p>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

Ami*_*mit 107

向右浮动div pull-right是推荐的方式,我觉得你正在做的事情可能是你只需要使用text-align:right;

  <div class="container">
     <div class="row-fluid">
      <div class="span6">
           <p>Text left</p>
      </div>
      <div class="span6 pull-right" style="text-align:right">
           <p>text right</p>
      </div>
  </div>
 </div>      
 </div>
Run Code Online (Sandbox Code Playgroud)

  • @ılǝ"..我们已经在下拉菜单中弃用了.pull-right**." 这不适用于其他拉动权利用法. (12认同)

Bil*_*oat 84

你的行中有两个span6 div,因此将占用一行组成的整个12个跨度.

向第二个span6 div添加pull-right不会对它做任何事情,因为它已经位于右侧.

如果你的意思是你想让第二个span6 div中的文本向右对齐,那么简单地向该div添加一个新类并给它text-align:right值,例如

.myclass {
    text-align: right;
}
Run Code Online (Sandbox Code Playgroud)

更新:

EricFreese指出,在Bootstrap的2.3版本(上周)中,他们添加了可以使用的文本对齐实用程序类:

  • .text-left
  • .text-center
  • .text-right

http://twitter.github.com/bootstrap/base-css.html#typography

  • 看起来他们在[2.3]中添加了用于对齐文本的实用程序类(http://blog.getbootstrap.com/2013/02/07/bootstrap-2-3-released/):`.text-left`,`.text -center`和`.text-right` (5认同)

ish*_*mwe 78

bootstrap 3有一个类来对齐div中的文本

<div class="text-right">
Run Code Online (Sandbox Code Playgroud)

将对齐右侧的文本

<div class="pull-right">
Run Code Online (Sandbox Code Playgroud)

将所有内容拉到右边,不仅仅是文本


Ber*_*ern 27

这样做无需添加内联样式

<div class="row-fluid">
    <div class="span6">
        <p>text left</p>
    </div>
    <div class="span6">
        <div class="pull-right">
            <p>text right</p>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

答案是<div>用"拉右"类嵌套另一个.将这两个类组合起来是行不通的.


Kév*_*ier 18

<p class="pull-left">Text left</p>
<p class="text-right">Text right in same line</p>
Run Code Online (Sandbox Code Playgroud)

这对我有用.

编辑:您的代码段的示例:

@import url('https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.css');
 .container {
    margin-top: 10px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
    <div class="row-fluid">
        <div class="span6 pull-left">
            <p>Text left</p>
        </div>
        <div class="span6 text-right">
            <p>text right</p>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)