简单的方案:

  <tr class="something">
    <td>A</td>
    <td>B</td>
    <td>C</td>
    <td>D</td>
  </tr>

我需要为<td>设置一个固定宽度。我试过了:

tr.something {
  td {
    width: 90px;
  }
}

Also

td.something {
  width: 90px;
}

for

<td class="something">B</td>

甚至

<td style="width: 90px;">B</td>

但是<td>的宽度是一样的。


当前回答

<div class="row" id="divcashgap" style="display:none"> <div class="col-md-12"> <div class="table-responsive"> <table class="table table-default" id="gvcashgapp"> <thead> <tr> <th class="1">BranchCode</th> <th class="2"><a>TC</a></th> <th class="3">VourNo</th> <th class="4" style="min-width:120px;">VourDate</th> <th class="5" style="min-width:120px;">RCPT Date</th> <th class="6">RCPT No</th> <th class="7"><a>PIS No</a></th> <th class="8" style="min-width:160px;">RCPT Ammount</th> <th class="9">Agging</th> <th class="10" style="min-width:160px;">DesPosition Days</th> <th class="11" style="min-width:150px;">Bank Credit Date</th> <th class="12">Comments</th> <th class="13" style="min-width:150px;">BAC Comment</th> <th class="14">BAC Ramark</th> <th class="15" style="min-width:150px;">RAC Comment</th> <th class="16">RAC Ramark</th> <th class="17" style="min-width:120px;">Update Status</th> </tr> </thead> <tbody id="tbdCashGapp"></tbody> </table> </div> </div> </div>

其他回答

这个组合解决方案为我工作,我想要等宽的列

<style type="text/css">

    table {
        table-layout: fixed;
        word-wrap: break-word;
    }

        table th, table td {
            overflow: hidden;
        }

</style>

结果:-

您可以创建一个colgroup并将这些类应用到col标记,而不是将col-md-*类应用到行中的每个td。

    <table class="table table-striped">
        <colgroup>
            <col class="col-md-4">
            <col class="col-md-7">
        </colgroup>
        <tbody>
        <tr>
            <td>Title</td>
            <td>Long Value</td>
        </tr>
        </tbody>
    </table>

演示

当我不需要处理IE时,我经常这样做

    <tr>
      <th scope="col" style="width: calc(1 * 100% / 12)">#</th>
      <th scope="col" style="width: calc(4 * 100% / 12)">Website</th>
      <th scope="col" style="width: calc(3 * 100% / 12)">Username</th>
      <th scope="col" style="width: calc(3 * 100% / 12)">Password</th>
      <th scope="col" style="width: calc(1 * 100% / 12)">Action</th>
    </tr>

这样你就可以有一个熟悉的12 col网格。

对我来说,将表的布局设置为自动,并针对特定列的<th>就可以了。我发现在任何行中定位<td>也可以。如果需要的话,请随意加入!important。

.table {
  table-layout: auto;
}

th {
 width: 10%;
}

引导程序4和5有一个宽度实用程序,用于调整html元素的宽度 例子:

<tr class="w-50">
    <td class="w-25">A</td>
    ...
</tr>