【问题标题】:CSS display table in IEIE中的CSS显示表格
【发布时间】: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
  • 这是一个适合所有人的 JSFiddle(花了两秒钟时间制作):jsfiddle.net/U9eVA
  • @RobertKoritnik 因此“7 及以下”​​
  • @Andy:既然你改变了你的评论。最初它只说 IE... 因此我的 IE8 评论... ;)

标签: html css internet-explorer css-tables


【解决方案1】:

IE7 不支持display:table,您的代码在 IE8、IE9 和 IE10 中看起来不错。因此,要么您必须使用实际的 &lt;table&gt;,或者,如果可以选择,请改用 floats。

恐怕别无他法。

编辑:显然这是针对您的页面布局。你不应该使用&lt;table&gt;display:table。只是浮动一些 DIV 人!

【讨论】:

  • 哦,这并不像您想象的那么简单...stackoverflow.com/questions/1205159/… .. esp。当您不想每次需要在 div 中添加另一个换行元素时都必须修改 css(填充)..
  • @mmcrae 这是一个非常常见的问题。如今,Flexbox 也可以在这方面提供帮助。 caniuse.com/#feat=flexbox
  • @ChuckLeButt Flexbox 仅在您不必支持 IE 8 或 9 时才出色
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-12
  • 2017-09-21
  • 1970-01-01
  • 2014-10-06
  • 2014-09-22
  • 1970-01-01
  • 2014-03-30
相关资源
最近更新 更多