css - Bootstrap - 表格内输入标签的宽度和对齐方式错误

标签 css twitter-bootstrap-3

我将输入标签放在表格中,我发现很难控制单元格的宽度和输入的对齐方式。

这是我的代码片段:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<form class="form-horizontal" method="post" action="./">
      <table class="table table-hover table-bordered table-striped">
        <thead>
          <tr>
            <th class="col-md-1">ID</th>
            <th class="col-md-3">Column A</th>
            <th class="col-md-1">Column B</th>
            <th class="col-md-1">Column C</th>
            <th class="col-md-3">Column D</th>
            <th class="col-md-3">Correction</th>
          </tr>
        </thead>
        <tbody>
        <tr>
          <td>1</td>
          <td>A1</td>
          <td class="text-right">B1</td>
          <td class="text-right">C1</td>
          <td class="text-right">90</td>
          <td><input type="number" name="correction1" class="col-md-5 text-right"></td>
        </tr>
        <tr>
          <td>2</td>
          <td>A2</td>
          <td class="text-right">B2</td>
          <td class="text-right">C2</td>
          <td class="text-right">50</td>
          <td><input type="number" name="correction2" class="col-md-5 text-right"></td>
        </tr>
        </tbody>
      </table>
    </form>

我希望输入标签的单元格(列名称“Correction”)与 D 列具有相同的宽度。并且还与输入标签右对齐。

最佳答案

您所要做的就是分配一些宽度并将 input float 到右侧。像您尝试的那样使用列类或文本对齐是行不通的。

.float-right{float: right;}
table input{width: 50%;}
table td{width: 10%;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<form class="form-horizontal" method="post" action="./">
      <table class="table table-hover table-bordered table-striped">
        <thead>
          <tr>
            <th class="col-md-1">ID</th>
            <th class="col-md-3">Column A</th>
            <th class="col-md-1">Column B</th>
            <th class="col-md-1">Column C</th>
            <th class="col-md-3">Column D</th>
            <th class="col-md-3">Correction</th>
          </tr>
        </thead>
        <tbody>
        <tr>
          <td>1</td>
          <td>A1</td>
          <td class="text-right">B1</td>
          <td class="text-right">C1</td>
          <td class="text-right">90</td>
          <td><input type="number" name="correction1" class="float-right"></td>
        </tr>
        <tr>
          <td>2</td>
          <td>A2</td>
          <td class="text-right">B2</td>
          <td class="text-right">C2</td>
          <td class="text-right">50</td>
          <td><input type="number" name="correction2" class="float-right"></td>
        </tr>
        </tbody>
      </table>
    </form>

关于css - Bootstrap - 表格内输入标签的宽度和对齐方式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47161297/

相关文章:

jquery - CSS (JQUERY) : border around icon

html - 单击更改边框颜色

javascript - 如何将类添加到列表元素?

html - 如何使内容 div 从页眉 div 延伸到页脚 div?

html - Bootstrap Jumbotron 区域直到页脚才会出现

html - HTML 页面中 CSS 文件的顺序是否重要?

javascript - 如何使用 JavaScript(和 jquery)检测一堆相同 div 类中的 div 溢出?

php - 如何使用 HTML 中的 Jquery 打开链接,从 MySql 和 PHP 获取 URL

css - bootstrap border-bottom 链接只有文本

twitter-bootstrap-3 - 可以在 Bootstrap 下拉菜单中使用按钮而不是 anchor 吗