如何使用twitter bootstrap对齐元素?

时间:2013-03-14 23:30:26

标签: html css twitter-bootstrap

我有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>

4 个答案:

答案 0 :(得分:61)

尝试上课'拉右'。

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

请参阅http://getbootstrap.com/css/#helper-classes-floats

答案 1 :(得分:8)

尝试这样的事情

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

答案 2 :(得分:0)

利用 justify-content-end

从bootstrap文档中,它说:

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

答案 3 :(得分:0)

在 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