javascript - 如何使 bootstrap 表头宽度与主体宽度对齐?

标签 javascript html css twitter-bootstrap angular-ui-bootstrap

我有一个 bootstrap 表,我有表头的背景色。由于我将表格宽度设置为自动,因此与主体宽度相比,标题宽度较小。我希望页眉宽度与主体宽度对齐。我在此处附加了一个 plunker 链接。

如何让header和body宽度对齐?

https://plnkr.co/edit/yIvC4XnOuEj6qVJH9rW8?p=preview

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
  <table class="table table-striped" style=" width:auto!important;">
    <thead>
      <tr style="background-color:red">
        <th>DETAILS</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
      <tr>
        <td>Mary</td>
        <td>Moe</td>
        <td>mary@example.com</td>
      </tr>
      <tr>
        <td>July</td>
        <td>Dooley</td>
        <td>july@example.com</td>
      </tr>
    </tbody>
  </table>
</div>

提前致谢!

最佳答案

如果您希望标题用于多列,请添加 colspan="3"

The colspan attribute defines the number of columns a cell should span.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
  <table class="table table-striped" style=" width:auto;">
    <thead>
      <tr style="background-color:red">
        <th colspan="3">DETAILS</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>John</td>
        <td>Doe</td>
        <td>john@example.com</td>
      </tr>
      <tr>
        <td>Mary</td>
        <td>Moe</td>
        <td>mary@example.com</td>
      </tr>
      <tr>
        <td>July</td>
        <td>Dooley</td>
        <td>july@example.com</td>
      </tr>
    </tbody>
  </table>
</div>

关于javascript - 如何使 bootstrap 表头宽度与主体宽度对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43862801/

相关文章:

javascript - Angular:如何从单选按钮组获取数据并将其作为参数传递给方法?

CSS:调整div中4个图像的位置

HTML 表格在打印时保持列宽

javascript - 当元素的底部边缘滚动到 View 中时使元素固定

javascript - 将 html 节点转换为一行字符串(缩小)

javascript - 在 react 中将函数作为 Prop 传递,无法读取未定义的属性 '_handleEvent'

javascript - 页面刷新时如何保持redux状态

html - Div 没有其 float 子项的总高度高

javascript - 我可以使用 vue js 显示 <p> 标签,但 2 秒后无法删除它

javascript - EaselJS sprite on("click) 返回 CORS 错误