【问题标题】:set height of inner div of table-cell to 100% of table-cell height in IE9/10在 IE9/10 中将表格单元格的内部 div 的高度设置为表格单元格高度的 100%
【发布时间】:2013-09-23 13:45:51
【问题描述】:

我认为这是 IE9/10 特定的问题。我正在尝试创建一个灵活的行布局,如下所示:

|----------------------------------|
|    FIXED HEIGHT                  |
|----------------------------------|
|    FIXED HEIGHT, SOMETIMES HIDDEN|
|----------------------------------|
|                                  |
|    FLEXIBLE HEIGHT               |
|                                  |
|----------------------------------|
|    FIXED HEIGHT                  |
|----------------------------------|

我还希望它的外部容器具有适合浏览器视图端口的灵活高度和宽度。

天真地,可能,我认为既然我只支持 Chrome、Firefox、Safari 和 IE9/10,那么display: tabledisplay: table-rowdisplay: table-cell 可能是一个不错的选择,所以我来了最多:

jsFiddle:http://jsfiddle.net/Nugps/2/

HTML:

<div class="stage">
    <div class="table">
        <div class="row">
            <div class="cell">
                <div class="content1">one</div>
            </div>
        </div>
        <div class="row">
            <div class="cell">
                <div class="content1">two</div>
            </div>
        </div>
        <div class="row flexible">
            <div class="cell">
                <div class="content2">three</div>
            </div>
        </div>
        <div class="row">
            <div class="cell">
                <div class="content1">four</div>
            </div>
        </div>
    </div>
</div>

CSS:

* {
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

.stage {
    position: absolute;
    top: 15px;
    right: 15px;
    bottom: 15px;
    left: 15px;
}

.table {
    display: table;
    height: 100%;
    width: 100%;
    background: lightblue;
}

.row {
    display: table-row;
}

.cell {
    display: table-cell;
    border: 3px solid red;
    height: 50px;
}

.row.flexible {
    height: 100%;
}

.row.flexible .cell {
    height: 100%;
}

.content2 {
    background: lightgreen;
    height: 100%; /* setting this in IE causes the content to be 100% of the table rather than the table cell height */
}

如果你在 Chrome 中打开这个 jsFiddle,一切都和预期的一样。但是在 IE10 中,我也怀疑 IE9 的高度搞砸了(.content2 高度是表格的 100%,而不是单元格)。

除了使用 javascript 手动设置内容的高度之外,还有什么好的解决方法吗?或者有没有更好的 CSS 布局可以使用?由于 IE9,我无法使用较新的 flexbox。

【问题讨论】:

    标签: html css


    【解决方案1】:

    我想知道 content2 类是否真的需要样式,你能不能只将背景颜色添加到 .row.flexible .cell 并一起摆脱 .content2 样式。

    这是我的解决方案: http://cdpn.io/Ewrsa

    它适用于 IE9/10

    【讨论】: