我想适应表 td 我发现这段代码适合第一个和最后一个,但我不知道如何适应第二个和第三个。
.table td {
text-align: center;
}
.tr td:first-child{
width:1%;
white-space:nowrap;
}
.tr td:last-child{
width:1%;
white-space:nowrap;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<table id="example1" class="table table-bordered table-hover">
<thead>
<th>HEAD1</th>
<th>HEAD2</th>
<th>HEAD3</th>
<th>HEAD4</th>
<th>HEAD5</th>
</thead>
<tbody>
<tr>
<td>DATA A</td>
<td>DATA B</td>
<td>DATA C</td>
<td>DATA D</td>
<td>DATA E</td>
</tr>
</tbody>
</table>
图片
最佳答案
尝试向 td 添加一些你想要健身的类(class) e.g.: <td class="fit">
并尝试:
tr td.fit {
width:1%;
white-space:nowrap;
}
或者您也可以这样做:<table style="width: 4%; white-space: nowrap;">
关于html - 如何使 <td> 适合内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51492303/