如何使内容适合

时间:2018-07-24 06:55:05

标签: html css html-table

我想拟合表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>

图片

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试向td添加一些您想要适合的课程e.g.: <td class="fit">,然后尝试:

tr td.fit {
    width:1%;
    white-space:nowrap;
}

或者您也可以:<table style="width: 4%; white-space: nowrap;">

相关问题