简单的方案:

  <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>

其他回答

<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>

我也遇到过这个问题,我用这个方法来克服…所以你可以试试

<td style=“min-width:120px;”>B</td>

引导4.0

在Bootstrap 4.0中,我们必须通过添加类d-flex来声明表行为flex-box,并删除xs, md,后缀以允许Bootstrap自动从视口派生它。

它看起来是这样的:

<table class="table">
    <thead>
        <tr class="d-flex">
            <th class="col-2"> Student No. </th>
            <th class="col-7"> Description </th>
            <th class="col-3"> Amount </th>
        </tr>
    </thead>

    <tbody>
        <tr class="d-flex">
            <td class="col-2">test</td>
            <td class="col-7">Name here</td>
            <td class="col-3">Amount Here </td>
        </tr>
    </tbody>
</table>

希望这将有助于其他人在那里!

干杯!

这些对我来说都不工作,并且在数据表上有许多cols,使%或sm类等于12个元素布局。

我正在使用Angular 5和Bootstrap 4的数据表,并且在表中有很多col。我的解决方案是在TH中添加一个具有特定宽度的DIV元素。例如,对于cols“Person Name”和“Event date”,我需要一个特定的宽度,然后在col标题中放一个div,整个col宽度然后调整为从TH上的div指定的宽度:

<table datatable [dtOptions]="dtOptions" *ngIf="listData" class="table table-hover table-sm table-bordered text-center display" width="100%">
    <thead class="thead-dark">
        <tr>
            <th scope="col">ID </th>
            <th scope="col">Value</th>
            <th scope="col"><div style="width: 600px;">Person Name</div></th>
            <th scope="col"><div style="width: 800px;">Event date</div></th> ...

如果在表上使用<table class="table">, Bootstrap的表类将为表添加100%的宽度。您需要将宽度更改为自动。

此外,如果表的第一行是标题行,则可能需要将宽度添加到th而不是td。