【问题标题】:Chromium calculates table width incorrectly?Chromium 计算表格宽度不正确?
【发布时间】:2015-07-29 06:36:50
【问题描述】:

所以我有一个宽表,在 Chromium 的最新版本中显示有点错误。 37 版可以正确渲染,44 版则不能。

问题是最后一列不包含在table/thead/tbody宽度中。所以标题比它应该的要窄。如果我设置table-layout:fixed,这个错误就会消失,但我必须使用auto

看起来像一个铬错误,但无论如何,有解决方法吗?

JsFiddle以下:

table,
th,
td {
  border: 1px solid black;
  border-collapse: collapse;
}
th,
td {
  padding: 5px;
}
<table>
  <caption style="background: lightgreen;">
    Caption
  </caption>
  <thead>
    <tr>
      <th>
        Title
      </th>
      <th>
        Description
      </th>
      <th>
        Lorem Ipsum
      </th>
      <th>
        Lorem Ipsum
      </th>
      <th>
        Actions
      </th>
      <th>
        Actions
      </th>
      <th>
        Actions
      </th>
      <th>
        Actions
      </th>
      <th>

      </th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        Lorem ipsum dolor sit amet
      </td>
      <td>
        <span>Lorem ipsum dolor sit amet, consectetur
                        adipiscing elit. Vestibulum dignissim mauris vel auctor
                        dapibus. Morbi scelerisque interdum magna, sed pulvinar
                        libero fringilla quis. Vivamus maximus lorem tempor
                        nibh eleifend, ac euismod velit dictum.</span>
      </td>
      <td>qwe</td>
      <td>qwe</td>
      <td>qwe</td>
      <td>qwe</td>
      <td>qwe</td>
      <td>qwe</td>
    </tr>
  </tbody>
</table>
</body>

</html>

【问题讨论】:

标签: html css google-chrome chromium


【解决方案1】:

据我所知,这是一个令人着迷的 Chrome 错误。

这是一种解决方法using &lt;col&gt; 为描述列提供width: 100%(根据需要替换宽度大小)这可以阻止错误并且不会破坏任何列宽:

table {
  border-collapse: collapse;
  border: solid 10px #F00
}
th,
td {
  border: 1px solid black;
  padding: 5px;
}
.description {
  width: 100%
}
<table>
  <caption style="background: lightgreen;">Caption</caption>
  <col>
  <col class="description">
        <thead>
          <tr>
            <th>1Title</th>
            <th>2Description</th>
            <th>3Lorem Ipsum</th>
            <th>4 Lorem Ipsum</th>
            <th>5 Actions</th>
            <th>6 Actions</th>
            <th>7 Actions</th>
            <th>8 Actions</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>1 Lorem ipsum dolor sit amet</td>
            <td>2Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum dignissim mauris vel auctor dapibus. Morbi scelerisque interdum magna, sed pulvinar libero fringilla quis. Vivamus maximus lorem tempor nibh eleifend, ac euismod velit dictum.

            </td>
            <td>3qwe</td>
            <td>4qwe</td>
            <td>5qwe</td>
            <td>6qwe</td>
            <td>7qwe</td>
            <td>8qwe</td>
          </tr>
        </tbody>
</table>

【讨论】:

  • 谢谢!你为我节省了大量时间!
  • @ValeriyStreltsov - 不用担心 :) 如果 width: 100% 引起任何其他问题,您可以将其更改为更小的东西,它应该没有任何问题。
【解决方案2】:

我认为这是数量的问题,因为第一行比第二行多一个。 TH 为空,TD 不存在。请测试一下:

https://jsfiddle.net/Lk8coxL6/2/

我在空 th 中添加了一个空格,并添加了缺少的 td。

<th> &nbsp; </th>

<td> qwe </td>

祝你好运

【讨论】:

  • 没有解决问题。我又添加了一张截图。
  • 没有理由投反对票。下一次,会帮你表弟的。
  • 啊,好的,对不起我的评论
  • @MarcosPérezGude - 这个答案不能解决问题中提出的问题或解释这里存在的错误。通常,在提出一些尝试的选项时,最好将它们作为评论留下,特别是如果您不确定:)
猜你喜欢
  • 2012-04-08
  • 2015-02-20
  • 2014-03-23
  • 1970-01-01
  • 2011-10-05
  • 1970-01-01
  • 2011-10-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多