表格单元的100%高度在IE中不起作用

时间:2015-03-21 15:17:46

标签: css internet-explorer

我有一个内容小组,充当可滚动内容的视口。此视口需要始终拉伸到其父级的整个宽度和高度。我的网站其余部分的布局是这样的,我需要设置父级显示:table-cell。这在Firefox和Chrome中运行良好,但IE不尊重高度:100%规则。这是我的代码:

<body>
    <div class="wrapper">
            <div class="content">
                <main>
                    <div class="article-wrapper">
                        <article id="home">
                            <h1>This is the home page</h1>
                            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptate quae ipsa dolor quidem ipsum, repudiandae maiores ad aliquam in necessitatibus incidunt. Quibusdam alias beatae temporibus culpa, esse ipsam, rem ducimus.</p><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptate quae ipsa dolor quidem ipsum, repudiandae maiores ad aliquam in necessitatibus incidunt. Quibusdam alias beatae temporibus culpa, esse ipsam, rem ducimus.</p>
                        </article>                                                  
                    </div>
                </main>
            </div>
    </div>
</body>

CSS:

* {
  box-sizing: border-box;
}
html, body {
  height: 100%;
}
main {
  background-color: rgba(0, 0, 0, 0.85);
}
.content {
  display: table;
}
.wrapper {
  position: relative;
  height: 100%;
}
.content {
  width: 1060px;
  position: absolute;
  padding: 140px 0 200px 0;
  height: 100%;
  top: 0;
  left: 50%;
  margin-left: -530px;
}
main {
  width: 742px;
  padding: 2em;
  position: relative;
  font-size: 1.5em;
  display: table-cell;
  vertical-align: middle;
}
main .article-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 10px;
  background-color: red;
}
main .article-wrapper article {
  background-color: purple;
  width: 100%;
  height: 100%;
  overflow-y: auto;
}

JS小提琴:https://jsfiddle.net/Inigo/r0cujj6x/

这在Firefox和Chrome中正确显示,但在我测试过的所有IE版本中(来自IE9 - IE11(最新版)),紫色框未填充红色容器。

如何让紫色article伸展到正确的高度?感谢。

编辑:我还尝试将article设置为position:absolutetop:0, right:0, bottom:0 left:0,但无济于事;高度仍未正确显示。

1 个答案:

答案 0 :(得分:0)

position: relative添加到main .article-wrapperonly for IE) 并从padding元素中删除main

这是一个工作小提琴:https://jsfiddle.net/gregmatys/r0cujj6x/1/