当宽度为自动时,如何将按钮定位到桌子的底部?

时间:2017-05-11 09:50:46

标签: html css twitter-bootstrap angular-ui-bootstrap bootstrap-modal

我在此处添加了我的plunker链接https://plnkr.co/edit/TD6iQJvIExwTeJ9QPbRS?p=preview

我希望提交按钮显示在表格的右下方。我的表格宽度根据数据而变化。我桌子的宽度是自动的。那么我每次如何将按钮置于右下角。

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Basic Table</h2>
  <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>            
  <table class="table" style="width:auto;">
    <thead>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
      <tr>
        <td>Mary</td>
        <td>Moe</td>
        <td>mary@example.com</td>
      </tr>
      <tr>
        <td>July</td>
        <td>Dooley</td>
        <td>july@example.com</td>
      </tr>
    </tbody>
  </table>
  <div class="col-sm-1">
    <button class="btn btn-success pull-right">SUBMIT</button>
  </div>
</div>

</body>
</html>

2 个答案:

答案 0 :(得分:1)

您可以尝试使用此代码。

尝试从tbody中删除最后一个tr并检查宽度和按钮位置。

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2>Basic Table</h2>
  <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>            
  <table class="table" style="width:auto;">
    <thead>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Email</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
      <tr>
        <td>Mary</td>
        <td>Moe</td>
        <td>mary@example.com</td>
      </tr>
      <tr>
        <td>July</td>
        <td>Dooley</td>
        <td>july@example.com</td>
      </tr>
      <tr>
        <td>July jan</td>
        <td>Dooley Hello</td>
        <td>julyjan12345678@example.com</td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <td colspan="3" align="right"><button class="btn btn-success pull-right">SUBMIT</button></td>
      </tr>
    </tfoot>
  </table>
</div>

</body>
</html>

答案 1 :(得分:0)

将Grid类更改为col-sm-12,并将表的宽度设置为100%。 添加了预览, https://plnkr.co/edit/M3p2bpj460niGCu59irR?p=preview