【发布时间】:2015-05-15 03:07:02
【问题描述】:
我写这个问题是为了整合这个网站上的多个类似问题,最后得到一个正确的yes或no答案。 一些现有的答案被错误地标记为正确,而实际上它们不能正常工作。
已阅读,相关问题。
- height: 100% for <div> inside <div> with display: table-cell
- Making inner div heights 100% with css in a table-cell
- Full height div inside td
- DIV stretch to height 100% in a table cell
- Getting div to occupy full cell height
- How to make <div> fill <td> height
给定以下标记:
<div class="equal-height">
<div class="col-50">
<div class="cell-fill">
...
</div>
</div>
<div class="col-50">
<div class="cell-fill">
...
</div>
</div>
</div>
是否有可能在以下浏览器中仅使用 CSS 使具有 cell-fill 类的 div 跨越其容器高度的 100%?
- Chrome - 最新
- Opera - 最新
- Safari - 最新
- Firefox - 最新
- IE9+
我能得到的最接近的是this example:
给出的版本适用于最新的 Chrome、Opera、Safari 和 Firefox。它也适用于 IE11,但无法在 IE9 和 IE10 上填充全高。
在这些浏览器中,如果外部 equal-height 元素的高度设置为大于最小列的像素值,则 cell-fill 的高度将会增加,因此也许可以根据该行为找到解决方案。
当前 CSS
/*
* 1. Stop columns and rows collapsing.
* 2. Set height so Chrome and IE11 work.
*/
.equal-height {
display: table;
table-layout: fixed; /*1*/
height: 1px; /*2*/
width: 100%;
}
/*
* 1. Inherit and pass on height.
* 2. Fill full height.
*/
.col-50{
width:50%;
height:100%; /*1*/
display:table-cell; /*2*/
}
/*
* 1. Force Layout.
* 2. Fill full height.
* 3. So we can see it.
*/
.cell-fill{
display:table; /*1*/
height:100%; /*2*/
background-color: #ff69b4 /*3*/
}
【问题讨论】: