【问题标题】:Align text input in <td> to right in twitter bootstrap?在 twitter bootstrap 中将 <td> 中的文本输入对齐?
【发布时间】:2017-08-16 01:01:22
【问题描述】:
我正在尝试将文本输入向右对齐,但由于某种原因它没有这样做。
我在<td>中使用过style="text-align: right"
查看示例:
https://jsfiddle.net/DTcHh/31200/
代码
<table class="table">
<thead>
<tr>
<th>Field 1</th>
<th style="text-align:right">Field 1</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text 1</td>
<td style="text-align: right">
<div class="form-group" style="text-align: right">
<input style="width:60px" type="number" class="form-control" value="test">
</div>
</td>
</tr>
</tbody>
</table>
【问题讨论】:
标签:
html
css
twitter-bootstrap
twitter-bootstrap-3
html-table
【解决方案2】:
将 inline-block 添加到您的 div 元素,默认情况下 div 是块元素,因此它占用其父元素的完整宽度
<div class="form-group" style="text-align: right;display:inline-block;">
<input style="width:60px" type="number" class="form-control" value="test">
</div>
https://jsfiddle.net/RACCH/y9fvo4dj/
【解决方案3】:
似乎只需添加float: right; 就可以了,请参阅
url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<table class="table">
<thead>
<tr>
<th>Field 1</th>
<th style="text-align:right">Field 1</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text 1</td>
<td style="text-align: right">
<div class="form-group" style="text-align: right; float:right">
<input style="width:60px" type="number" class="form-control" value="test">
</div>
</td>
</tr>
</tbody>
</table>
【解决方案5】:
您需要添加引导类,即。 “向右拉”
找到代码小提琴:
`https://jsfiddle.net/DTcHh/31204/e`
【解决方案6】:
这两个解决方案适用于我的 Bootstrap 4 表:
要么:
<td>
<div class="float-right">
<input>
</div>
</td>
或者:
<td class="text-right">
<div class="d-inline-flex">
<input>
</div>
</td>