css - Firefox CSS 表格 - 内容转移

标签 css firefox css-tables

在 Chrome (v56) 和 Firefox (v51) 中比较以下代码时,Firefox 正在向下移动内容。 Chrome 的行为符合预期。

<html>
<head>
    <title>Test Page</title>
    <style type="text/css">
    .content {
        height: 200px;
        width: 200px;
    }
    .table {
        width: 100%;
        height: 50%;
        display: table;
    }
    .leftCell {
        border: 1px solid #cccccc;
        width: 50%;
        height: 100%;
        overflow: auto;
        display: table-cell;
    }
    .rightCell {
        width: 50%;
        height: 100%;
        display: table-cell;
        border: 1px solid #cccccc;
    }
</style>
</head>
<body>
<div class="content">
    <div class="table">
        <div class="leftCell">
            <div>row</div>
            <div>row</div>
            <div>row</div>
            <div>row</div>
        </div>
        <div class="rightCell"></div>
    </div>
</div>
</body>
</html>

Chrome : Chrome

火狐: Firefox

仅当“rightCell”div 为空时才会出现此问题。如果我删除该 div,内容将显示在预期位置。 以前有人遇到过这个问题吗?有什么已知的修复方法吗? 问候

最佳答案

这是因为表格单元格的内容沿其基线垂直对齐。如果其中有文字,那就是第一行。如果其中没有文本,那就是单元格的底部边框,您可以在发布的图片中看到它。这就是显示您的代码段结果的原因。

为避免这种情况,将 vertical-align: top 分配给两个单元格(参见我的代码片段)

.content {
  height: 200px;
  width: 200px;
}

.table {
  width: 100%;
  height: 50%;
  display: table;
}

.leftCell {
  border: 1px solid #cccccc;
  width: 50%;
  height: 100%;
  overflow: auto;
  display: table-cell;
  vertical-align: top;
}

.rightCell {
  width: 50%;
  height: 100%;
  display: table-cell;
  border: 1px solid #cccccc;
  vertical-align: top;
}
<div class="content">
  <div class="table">
    <div class="leftCell">
      <div>row</div>
      <div>row</div>
      <div>row</div>
      <div>row</div>
    </div>
    <div class="rightCell"></div>
  </div>
</div>

关于css - Firefox CSS 表格 - 内容转移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42334730/

相关文章:

html - td 内的图像是 td 的高度

javascript - 如何在纯 JavaScript 中向元素添加和删除事件类

css - Firefox 上的按钮太高

html - 如何在 HTML5 中使用 div 和 span

html - 使用 ASP.NET MVC 的 Div 表

html - 行之间的html表格中的间距

html - 为什么这个表格单元格方法会改变 div 高度?

html - 制作内容中心

javascript - 调用方法 HTMLAnchorElement.focus 的权限被拒绝

javascript - 如何在新打开的窗口中调试 JS?