【问题标题】:Table with dynamic row height issue具有动态行高问题的表格
【发布时间】:2016-10-08 15:41:48
【问题描述】:

我正在使用引导程序创建一个包含一些具有动态高度的列的表。当任何表格单元格必须折叠,使所有行都变高时,其他单元格高度的内容保持不变。

这是正在发生的事情的一个例子:

/* CSS used here will be applied after bootstrap.css */

.input-group input, .input-group span{
  border: none;
}

span.input-group-addon {
  background-color: red;
}

.table-bordered>tbody>tr>td, .table-bordered>tbody>tr>th, .table-bordered>tfoot>tr>td, .table-bordered>tfoot>tr>th, .table-bordered>thead>tr>td, .table-bordered>thead>tr>th{
  vertical-align: middle;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table table-bordered">
  <tbody>
    <tr>
      <th>Big word to test multiple line</th>
      <td>Teste</td>
      <td class="checkbox-table">
        <div class="input-group">
          <input type="number" class="form-control" min="0/">
          <span class="input-group-addon"><input type="checkbox">NS</span>
        </div>
      </td>
    </tr>
  </tbody>
</table>

http://www.bootply.com/yItLpVcKof

我希望跨度具有单元格高度,因此它的所有背景都变为红色(但不是所有单元格)。

我尝试在某些单元格和行上添加height:100%,但不起作用。我想自动保持行高,所以添加固定高度不是解决方案。我已经看到了一些使用 div 的解决方案,例如 this,但我想保留一个表格。

【问题讨论】:

  • 我不明白这个问题。那么你想让带红色背景的跨度填充单元格吗?
  • 它希望它填满跨度的整个高度
  • 我找到了解决方案,请查看下面的帖子。仍然无法标记它是正确的。

标签: html css twitter-bootstrap html-table


【解决方案1】:

您可以将此checkbox 写入个人td 并将class = "input-group-addon" 提供给该td

<tr>
  <th>Energia Elétrica</th>
  <td>Test</td>
  <td class="checkbox-table">
    <div class="input-group">
      <input type="number" class="form-control" min="0/">

    </div>
  </td>
  <td class="input-group-addon"><input type="checkbox">NS</td>
</tr>

检查这个http://www.bootply.com/xGm9xGA1G7

【讨论】:

  • 我可以工作,但它会使事情变得有点复杂,因为我们将输入与复选框分开。但如果没有其他事情发生,它会做,谢谢。如果我没有其他解决方案,我会接受
  • 我想出了一个解决方案,所以这不是必需的。无论如何谢谢=)
【解决方案2】:

here 的帮助下,我发现了如何完成这项工作。

这是最终结果:

    /* CSS used here will be applied after bootstrap.css */

.table .checkbox-container {
  vertical-align: top;
  padding: 0;
}

.table .checkbox-container .input-group {
  height: 100%;
}

.table .checkbox-container .input-group-addon {
  border: none;
  border-radius: 0;
  background-color: red;
}

.table .checkbox-container .input-group > input {
  padding: 0;
  border: none;
  border-radius: 0;
  outline: none;
  height: 100%;
}

.table .box {
  height: 100%;
  padding: 0;
  display: inline-block;
}

.table-bordered>tbody>tr>td, .table-bordered>tbody>tr>th, .table-bordered>tfoot>tr>td, .table-bordered>tfoot>tr>th, .table-bordered>thead>tr>td, .table-bordered>thead>tr>th{
  vertical-align: middle;
}
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
    <table class="table table-bordered">
  <tbody>
    <tr>
      <th>Big word to test multiple line</th>
      <td>Teste</td>
      <td class="checkbox-container">
        <div class="box">
          <div class="input-group fill-during">
            <input id="B17" type="number" class="form-control" min="0/">
            <span class="input-group-addon"><input type="checkbox">NS</span>
          </div>
        </div>
      </td>
    </tr>
  </tbody>
</table>

希望它对将来的任何人有所帮助。问题主要出在显示类型和高度上。

【讨论】:

    【解决方案3】:

    你可以在这里试试这个:height: auto;

    编辑:我误解了这个问题。如果引导程序添加了一些,您可以尝试重置单元格的填充。

    【讨论】:

    • 它确实添加了一些填充,我将其删除(但在示例中忘记了),但这不是问题。问题是由于显示类型(我猜)它有点为元素添加了自动填充(抱歉,技术性不是很强,但问题是我不明白显示的自动填充是如何工作的)
    • 可能上有边距,你得去掉
    • 不,问题不在于您在小提琴中看到的边距
    猜你喜欢
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 2017-07-19
    • 1970-01-01
    相关资源
    最近更新 更多