【问题标题】:css absolute position child height in parent with display table-cell not working in IE父级中的css绝对位置子级高度,显示表格单元格在IE中不起作用
【发布时间】:2015-12-09 17:59:20
【问题描述】:

关于在父显示中定位绝对 div 的快速问题:IE 中的表格单元格。

我已经创建了我正在尝试创建的布局的 jsfiddle,它在 chrome 和 firefox 中工作,但在 IE 中它破坏了子级的 .list-container 绝对高度(这是 se在具有 display: table-cell 的父级内部时填充从顶部 118px 向下的所有空间。

我是否缺少任何 IE 样式规则来帮助它呈现绝对的孩子?这在 IE 中是可能的吗?

jsFiddle

html, body{ 
    height:100%; 
    margin:0; 
    padding:0px; 
} 
.table{ 
   display : table; 
    width : 100%; 
    height : 100%; 
} 
.row{ 
    display : table-row; 
    width : 100%; 
    height : 100%; 
} 
.table-cell{ 
    height:100%; 
    width:50%; 
    border:1px solid #000; 
    display : table-cell; 
    position: relative; 
} 
.header{ 
    position:relative; 
    top:0px; 
    height:112px;  
    margin:0px; 
    border:3px solid blue; 
    background: rgba(0,0,230, .2); 
} 
.list-container{ 
    position:absolute; 
    top:118px; 
    left:0px;
    bottom:0px; 
    right:0px;  
    margin:0px; 
    overflow:auto; 
    overflow-x:hidden; 
    border:3px solid #CCC;
    background: rgba(0,0,0,.1); 
} 

<body>
    <div class="table">
    <div class="row">
        <div class="table-cell">
            <header class="header"></header>
            <div class="list-container">
                <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
            </div>
        </div>
        <div class="table-cell">
        </div>
    </div>
    </div>
</body>

【问题讨论】:

  • 我注意到父 div.table-cell 在 chrome 和 firefox 中计算的样式是表格的全高,但在 IE 中,div.table-cell 的高度为子相对 header.header 元素。

标签: css internet-explorer position absolute tablecell


【解决方案1】:

我发现在 IE 中,表格单元格只接受子元素的高度。如果您添加一个包装器 div.table,其样式为 100%,并且在 header.header 和 div.list-container 周围具有高度,它将为父表提供 100% 的父 div.table-cell 高度。

这是一个显示更改的 jsfiddle:

jsFiddle

html,
body {
  height: 100%;
  margin: 0;
  padding: 0px;
}
.table {
  display: table;
  width: 100%;
  height: 100%;
}
.row {
  display: table-row;
  width: 100%;
  height: 100%;
}
.table-cell {
  height: 100%;
  width: 50%;
  border: 1px solid #000;
  display: table-cell;
  position: relative;
  vertical-align: top;
}
.header {
  position: relative;
  top: 0px;
  height: 112px;
  margin: 0px;
  border: 3px solid blue;
  background: rgba(0, 0, 230, .2);
}
.list-container {
  position: absolute;
  top: 118px;
  left: 0px;
  bottom: 0px;
  right: 0px;
  margin: 0px;
  overflow: auto;
  overflow-x: hidden;
  border: 3px solid #CCC;
  background: rgba(0, 0, 0, .1);
}
<body>
  <div class="table">
    <div class="row">
      <div class="table-cell">
        <header class="header"></header>
        <div class="list-container">
          <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
        </div>
      </div>
      <div class="table-cell">
      </div>
    </div>
  </div>
</body>

【讨论】:

    猜你喜欢
    • 2013-06-01
    • 1970-01-01
    • 2015-05-24
    • 2012-01-27
    • 2012-06-16
    • 2014-10-06
    • 2015-02-07
    • 1970-01-01
    • 2014-05-07
    相关资源
    最近更新 更多