1

我在这里包含了我的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>[email protected]</td> 
     </tr> 
     <tr> 
     <td>Mary</td> 
     <td>Moe</td> 
     <td>[email protected]</td> 
     </tr> 
     <tr> 
     <td>July</td> 
     <td>Dooley</td> 
     <td>[email protected]</td> 
     </tr> 
    </tbody> 
    </table> 
    <div class="col-sm-1"> 
    <button class="btn btn-success pull-right">SUBMIT</button> 
    </div> 
</div> 

</body> 
</html> 
+0

请接受我们对你的问题的答案,让其他人知道这个问题解决 – ZimSystem

+0

@ZimSystem我accepted.Sorry – radiance88

回答

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>[email protected]</td> 
 
     </tr> 
 
     <tr> 
 
     <td>Mary</td> 
 
     <td>Moe</td> 
 
     <td>[email protected]</td> 
 
     </tr> 
 
     <tr> 
 
     <td>July</td> 
 
     <td>Dooley</td> 
 
     <td>[email protected]</td> 
 
     </tr> 
 
     <tr> 
 
     <td>July jan</td> 
 
     <td>Dooley Hello</td> 
 
     <td>[email protected]</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>

+0

您还可以删除ALIGN =“右”作为它不是必需的。 –

相关问题