vivoconunxino vivoconunxino - 10 days ago 7
CSS Question

Two Bootstrap buttons aligned to the right in a row

I can't get two buttons to stay when possible one next to other aligned at the right side of the panel.

Here is a fiddle with my current solution.

<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">my panel title</h3>
</div>
<div class="panel-body">
<form action="#" class="form">
<div class="row">
<div class="col-sm-offset-10 col-sm-1">
<button type="submit" class="btn btn-default" id="btn1" name="btn1" value="1">button1</button>
</div>
<div class="col-sm-1">
<button class="btn btn-primary" id="btn2" name="btn2" value="2" type="submit">button2</button>
</div>
</div>
</form>
</div>
</div>

Answer

Put both buttons in a column (col-*-*) and use text-right class to parent div.

<div class="col-sm-12 text-right">
 <button type="submit" class="btn btn-default" id="btn1" name="btn1" value="1">button1</button>
 <button class="btn btn-primary" id="btn2" name="btn2" value="2" type="submit">button2</button>
</div>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title">my panel title</h3>
  </div>
  <div class="panel-body">
    <form action="#" class="form">
      <div class="row">
        <div class="col-sm-12 text-right">
          <button type="submit" class="btn btn-default" id="btn1" name="btn1" value="1">button1</button>
          <button class="btn btn-primary" id="btn2" name="btn2" value="2" type="submit">button2</button>
        </div>
      </div>
    </form>
  </div>
</div>