html - 如何使 <td> 适合内容

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

最佳答案

尝试向 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/

相关文章:

php - 在整个文档中去除标签的快速方法

javascript - 使用 JS 在动态生成的表格中添加按钮

css - 在 outlook 上隐藏移动表格

html - 内部元素应该被外部元素边界半径修剪

css - 制作始终为 "on top"的部分

javascript - 跨浏览器兼容性问题

javascript - 我们如何将两个响应式和卡住的图片与 z-index 放在一起?

css - 如何在 div 标签上添加带边框的三 Angular 形

jQuery 切换光标图标

angularjs - Angular 指令在 HTML 表格中无法正常工作