具有表单输入最小宽度的Bootstrap响应表

rob*_*lli 12 html twitter-bootstrap twitter-bootstrap-3

我正在尝试创建一个包含多个列的表单输入的响应表.根据我的理解,响应表会缩小,直到它的列不能再进一步,然后它会添加一个滚动条.但是,列缩小到无法在输入字段中看到值的位置,因此我需要一种方法在这些列上施加最小宽度,而不是由列标题文本长度确定.

我尝试将min-width:"10%"或"150px"添加到列中的所有元素,但这不起作用.这是我的设置:

<form class="form-horizontal">
    <div class="table-responsive">
        <table class="table table-bordered table-striped table-highlight">
            <thead>
                <th>Name</th>
                <th>Date</th>
                <th>Cost</th>
                <th>Billing Type</th>
                <th>Tax</th>
                <th>Other Col</th>
                <th>Other Col</th>
                <th>Other Col</th>
                <th>Total</th>
            </thead>
            <tbody>
                <tr>
                    <td><input type="text" class="form-control" value="Some Long Name Here"/></td>
                    <td><input type="text" class="form-control" value="13-Jul-2015"/></td>
                    <td><input type="text" class="form-control" value="$12355.12"/></td>
                    <td>
                        <select class="form-control">
                            <option>Monthly</option>
                            <option>Yearly</option>
                        </select>
                    </td>
                    <td><input type="text" class="form-control" value="another long value"/></td>
                    <td><input type="text" class="form-control" value="some val"/></td>
                    <td><input type="text" class="form-control" value="some val"/></td>
                    <td><input type="text" class="form-control" value="some val"/></td>
                    <td>$505.79</td>
                </tr>
            </tbody>
        </table>
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<form class="form-horizontal">
  <div class="table-responsive">
    <table class="table table-bordered table-striped table-highlight">
      <thead>
        <th>Name</th>
        <th>Date</th>
        <th>Cost</th>
        <th>Billing Type</th>
        <th>Tax</th>
        <th>Other Col</th>
        <th>Other Col</th>
        <th>Other Col</th>
        <th>Total</th>
      </thead>
      <tbody>
        <tr>
          <td><input type="text" class="form-control" value="Some Long Name Here" /></td>
          <td><input type="text" class="form-control" value="13-Jul-2015" /></td>
          <td><input type="text" class="form-control" value="$12355.12" /></td>
          <td>
            <select class="form-control">
                            <option>Monthly</option>
                            <option>Yearly</option>
                        </select>
          </td>
          <td><input type="text" class="form-control" value="another long value" /></td>
          <td><input type="text" class="form-control" value="some val" /></td>
          <td><input type="text" class="form-control" value="some val" /></td>
          <td><input type="text" class="form-control" value="some val" /></td>
          <td>$505.79</td>
        </tr>
      </tbody>
    </table>
  </div>
</form>
Run Code Online (Sandbox Code Playgroud)

如您所见,当表缩小时,某些字段值会被切断.任何帮助表示赞赏.

编辑:我继续使用表,由于一些遗留代码保存.但是,如果需要,我愿意接受任何解决方案.

kat*_*des 13

.form-control的默认css会强制执行此行为,因此您需要更改输入字段的css,如:

input.form-control {
  width: auto;
}
Run Code Online (Sandbox Code Playgroud)

  • 这样做了,谢谢!简单的实施.我还能够修改它以使用特定宽度或使用最小宽度等等... (2认同)