简单的方案:

  <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>的宽度是一样的。


当前回答

在引导表4.x中

如果您在初始化参数中创建表,而不是使用HTML。

你可以在columns属性中指定width参数:

$("table").bootstrapTable({
    columns: [
        { field: "title", title: "title", width: "100px" }
    ]
});

其他回答

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

.table {
  table-layout: auto;
}

th {
 width: 10%;
}

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

在我的案例中,我能够通过使用min-width: 100px而不是width: 100px来修复单元格th或td的问题。

.table td, .table th {
    min-width: 100px;
}

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

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

我已经为这个问题纠结了一段时间了,所以以防万一有人和我犯同样愚蠢的错误…… 在<td>中,我应用了带有white-space:pre style的元素。这使得我所有的table/tr/td技巧都被丢弃了。当我删除该样式时,突然间我所有的文本都在td中被很好地格式化了。

所以,总是检查主容器(如table或td),但也总是检查你是否在更深的地方取消你的beautifull代码:)