两个Bootstrap按钮连续排成一行

时间:2016-11-29 13:12:57

标签: html css twitter-bootstrap

我无法让两个按钮停留在面板右侧的另一个按钮旁边。

这是我当前解决方案的fiddle

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

3 个答案:

答案 0 :(得分:5)

将两个按钮放在一列(col-*-*)中,并将text-right类用于父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>

答案 1 :(得分:1)

更新您的

if(array_key_exists('first_name', $tet['data'])) {
  //code...
}

<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则不能

答案 2 :(得分:0)

将您的行类更新为:

<div class="row">
    <div class="col-sm-offset-10 col-sm-1" style="text-align: right; padding: 0px; ">
        <button type="submit" class="btn btn-default" id="btn1" name="btn1" value="1">button1</button> 
    </div> 
    <div class="col-sm-1" style="padding-left: 0px; ">
        <button class="btn btn-primary" id="btn2" name="btn2" value="2" type="submit">button2</button> 
    </div> 
</div>