【发布时间】:2012-11-03 06:59:25
【问题描述】:
我有以下代码和 CSS。它在 Chrome 中运行良好,但在 IE 中不行。有没有办法让它在 IE 中也能工作?
CSS:
<style type="text/css">
.table {width:100%;height: 1%;background-color: lime;display: table;border-collapse: collapse;}
.row {display: table-row;}
.centercell {vertical-align: top;display: table-cell;background-color: #0f0;}
.top{background-color:yellow;width:100%;height:20px;z-index: 1;position: relative;}
.bottom{background-color:yellow;width:100%;height:20px;z-index: 1;position: relative;}
.middle{background-color:pink;width:100%;height: 100%;margin: -20px 0px;position: relative;padding: 20px 0px;}
.rightcell {vertical-align: top;background-color: #f00;display: table-cell;width:155px;background-image: url('img/bg1.gif');background-repeat:repeat-y}
.leftcell {vertical-align: top;background-color: #f00;display: table-cell;width:171px;}
</style>
HTML:
<div class="table">
<div class="row">
<div class="leftcell">
right column
</div>
<div class="centercell">
<div class="top">center top</div>
<div class="middle">center middle</div>
<div class="bottom">center bottom</div>
</div>
<div class="rightcell">
right column<br>
right column<br>
right column<br>
right column<br>
right column<br>
right column<br>
right column<br>
right column<br>
</div>
</div>
【问题讨论】:
-
IE7 及以下不支持
display: table,因此唯一的解决方法实际上是使用表格。 caniuse.com/css-table -
IE8 确实...quirksmode.org/css/display.html
-
这是一个适合所有人的 JSFiddle(花了两秒钟时间制作):jsfiddle.net/U9eVA
-
@RobertKoritnik 因此“7 及以下”
-
@Andy:既然你改变了你的评论。最初它只说 IE... 因此我的 IE8 评论... ;)
标签: html css internet-explorer css-tables