【发布时间】:2013-10-26 00:37:05
【问题描述】:
我在尝试用height:100% 创建一个div 时遇到了一些麻烦,该display:table-cell 包裹在其中。
我注意到它在 Firefox 和 IE 9 中不起作用。
Here's the fiddle with the problem。您会注意到它与 Chrome 或 Opera 一样正常工作。
代码有什么问题?
有什么办法可以解决吗?
我想保留父母的display:table 和display:table-cell,以便在可变高度容器上垂直居中内容。
HTML
<div class="table">
<div class="table-cell">
<div class="content"></div>
</div>
</div>
CSS
body, html {
margin:0;
padding:0;
height:100%;
}
.table {
display:table;
width:100%;
height:100%;
}
.table-cell {
display:table-cell;
vertical-align: middle;
width:100%;
}
.content {
height: 100%;
display: block;
overflow: hidden;
position: relative;
background: url(http://spaceinimages.esa.int/var/esa/storage/images/esa_multimedia/images/2012/11/solar_eclipse_corona/12092636-3-eng-GB/Solar_eclipse_corona_node_full_image.jpg);
background-size:cover;
}
【问题讨论】:
-
也相关,有一个很好的答案,在这里:stackoverflow.com/questions/27384433/…