This question already has answers here:
How to set maximum height for table-cell?

(10个回答)


已关闭6年。




我在使用 bootstrap 更改表行的高度时遇到麻烦。
我到目前为止的代码是:
    <table class="table table-bordered table-hover type-list2">
    <tr>
      <th>#</th>
      <th>DSP Type</th>
      <th>Email</th>
      <th>Code Type</th>
      <th>Dispatch Time</th>
      <th>Codes</th>
    </tr>
    <tr>
      <td>2</td>
      <td>Email</td>
      <td>[email protected]</td>
      <td>7 Day</td>
      <td>2014-05-20 15:42:59</td>
      <td>6</td>
    </tr>
    <tr>
      <td>2</td>
      <td>Manual</td>
      <td>[email protected]</td>
      <td>12 Month</td>
      <td>2014-05-20 15:42:59</td>
      <td>
      WXJ79-P33MM-RX7BP-QHW86-AAAAA
      <br>HW382-6TPF3-RHV63-3W8QP-AAAAA
      <br>FHKV2-K376Y-3Q984-36C7C-AAAAA
      <br>RHXCM-KC24C-6B7T9-TBFB3-AAAAA
      <br>MD8QM-VXBQW-B72Q7-CR3BM-AAAAA
      <br>GXFGV-KX7TP-82H2H-DRFHM-AAAAA
      <br>VQV2F-P7VKM-MBBMB-M7JYC-AAAAA
      <br>KG4VD-HWGMM-6MJCT-G7PVC-AAAAA
      </td>
    </tr>

和:
tr {
   max-height: 35px !important;
   height: 35px !important;
}

这是带有代码的 fiddle :http://www.bootply.com/xPgWHFFDah

最佳答案

解决方案是将div放入具有固定高度和溢出的内部,如下所示:

<td>
  <div style="height: 50px; overflow:auto;">
      WXJ79-P33MM-RX7BP-QHW86-AAAAA
      <br>HW382-6TPF3-RHV63-3W8QP-AAAAA
      <br>FHKV2-K376Y-3Q984-36C7C-AAAAA
      <br>RHXCM-KC24C-6B7T9-TBFB3-AAAAA
      <br>MD8QM-VXBQW-B72Q7-CR3BM-AAAAA
      <br>GXFGV-KX7TP-82H2H-DRFHM-AAAAA
      <br>VQV2F-P7VKM-MBBMB-M7JYC-AAAAA
      <br>KG4VD-HWGMM-6MJCT-G7PVC-AAAAA
  </div>
</td>

看一下更新的from here

09-15 19:16