html - 表格行填充剩余高度 Chrome vs. Firefox

标签 html css

我有一段代码在 Firefox 和 Chrome 上表现不同。

我想要的行为是 Firefox 上的行为。我想在 Chrome 上重现它但没有成功。

在下面的代码中,想法是 tr class="spacer" 填充 tr class="family" 行下方的剩余高度,这样它们就可以显示在 tr class="category" 行的顶部。

在 Chrome 上这是完全不一致的...

.category th {
  height: 200px;
  background: red;
}

.family {
  height: 70px;
  background: blue;
}
<table>
  <tbody>
    <tr>
      <th>Category</th>
      <th>Family</th>
      <th>Info</th>
    </tr>

    <tr class="category">
      <th rowspan="3">Category 1</th>
    </tr>
    <tr class="family">
      <td>Family 1</td>
      <td>Many different things</td>
    </tr>
    <tr class="spacer">
      <td colspan="3"></td>
    </tr>

    <tr class="category">
      <th rowspan="4">Category 2</th>
    </tr>
    <tr class="family">
      <td>Family 2</td>
      <td>Other things</td>
    </tr>
    <tr class="family">
      <td>Family 3</td>
      <td>Way more things</td>
    </tr>
    <tr class="spacer">
      <td colspan="3"></td>
    </tr>
  </tbody>
</table>

最佳答案

我认为问题在于您如何构建表格,但我没有使用 html 表格的解决方案。

我宁愿使用 css 网格属性。它需要多一点代码,但在我看来,它提供了更多选项、更好的响应能力等等。

我写了一些代码来显示你想要的表格。当然,您可以修改代码以使其更像您计划的那样工作,但这是一个基本结构。

HTML:

<div class="grid">
  <div>Category</div>
  <div>Family</div>
  <div>Info</div>

  <div class="first">
    <div class="grid-category">Category 1</div>
    <div class="family">Family 1</div>
    <div class="family">Many different things</div>
  </div>

  <div class="second">
    <div class="grid-category">Category 2</div>
    <div class="family">Family 2</div>
    <div class="family">Many different things</div>
    <div class="family">Family 3</div>
    <div class="family">Many different things</div>
  </div>
</div>

CSS:

.grid-category {
  min-height: 200px;
  background: red;
}

.family {
  height: 70px;
  background: blue;
}

.grid {
  display: inline-grid;
  grid-gap: 4px;
  grid-template-columns: auto auto auto;
  grid-template-rows: 16px auto auto;
}

.first,
.second {
  display: grid;
  grid-column: 1 / 4;
  grid-template-columns: auto auto auto;
  grid-template-rows: auto auto auto;
}

.grid-category {
  grid-row: 1 / 4;
}

关于html - 表格行填充剩余高度 Chrome vs. Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58096464/

相关文章:

javascript - 申请位置:absolute to a style via jQuery fails to center div horizontally upon first page load

jquery - 网站右侧空间

html - 如何使 2 个 div float ,左边的 div 具有固定的右边距?

html - 带有 Bootstrap 的部分高度

javascript - 如何在 PHP MVC 中使用 href 链接页面

javascript - 通过在 typescript 中渲染的字体颜色使用react

html - 当只应显示错误布局时显示输入焦点

javascript - jquery 我想禁用基于隐藏字段的表单中的 div

jquery - cropbox 图像覆盖覆盖拖动

css - 使用 CSS 背景图片的响应式图片