【问题标题】:How do I right align an element using twitter bootstrap?如何使用 twitter bootstrap 右对齐元素?
【发布时间】:2013-03-14 23:30:26
【问题描述】:

我有 3 个元素,我正在尝试将按钮对齐到屏幕右侧,但这样做时遇到了问题。

<div class="container">
  <div class="row-fluid">
    <h4>
      <img src="img.png" style="width:50px;">
      Title
      <a href="link_to_img.html" class="btn btn-success">Grab it!</a>
    </h4>
  </div>
</div>

【问题讨论】:

    标签: html css twitter-bootstrap


    【解决方案1】:

    试试“pull-right”类。

    <div class="pull-right">...</div>
    

    见http://getbootstrap.com/css/#helper-classes-floats

    【讨论】:

    【解决方案2】:

    试试这样的

    <a href = "link_to_img.html" class = 'btn btn-success pull-right'>Grab it!</a>
    

    【讨论】:

      【解决方案3】:

      利用 justify-content-end

      从引导文档中,它说:

      Bootstrap 3 使用 .navbar-left 和 .navbar-right 进行导航栏对齐。

      Bootstrap 4 使用各种帮助类。

      (对齐部分) https://www.quackit.com/bootstrap/bootstrap_4/tutorial/bootstrap_navbars.cfm

      这里有更多关于新对齐的信息 https://www.quackit.com/css/flexbox/tutorial/flexbox_alignment.cfm

      <!DOCTYPE html>
      <html>
      
      <head>
      <link rel="stylesheet" href="style.css">
      <script src="script.js"></script>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
      </head>
      
      <body>
      
        <style>
          .wrapper {
            display: flex;
            align-items: center;
            background-color: beige;
            height: 100vh;
          }
      
          .wrapper > div {
            padding: 20px;
            font-size: 4vw;
            color: white;
          }
      
          .red {
            background: orangered;
          }
      
          .green {
            background: yellowgreen;
          }
      
          .blue {
            background: steelblue;
          }
      
          body {
            margin: 0;
          }
        </style>
        <div class="wrapper justify-content-end">
          <div class="red">1</div>
          <div class="green">2</div>
          <div class="blue">3</div>
        </div>
      </body>
      
      </html>
      

      https://plnkr.co/edit/LtfW2fj9f3E9Ehj1M8jN?p=catalogue

      【讨论】:

        【解决方案4】:

        在 Bootstrap v4 中:

        <div class="float-right">Float right on all viewport sizes</div>
        

        Bootstap v4 docs

        在 Bootstrap v5 中:

        <div class="float-end">Float end on all viewport sizes</div>
        

        Bootstrao v5 docs

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-06-18
          • 2014-12-02
          • 2013-03-04
          • 2011-12-03
          • 1970-01-01
          • 2017-03-19
          • 2021-05-13
          相关资源
          最近更新 更多