html - 如何在动态表格单元格中创建高度为 100% 的 div?

标签 html css internet-explorer html-table opera

我有动态和静态表格单元格。我需要在动态表格单元格中创建高度为 100% 的 div。

我有最小的解决方案 - 这只适用于 Chrome 和 Firefox。在 Opera 和 IE 中,子 div 有一个顶层表格大小。没有js的opera和ie有解决方案吗?

好:

good

差:

enter image description here


更新 #1 对于 Chrome、FF 和 Opera(Presto):

<table class='m-table'>
    <tr>
      <td class='m-top-cell'>
        <div class="b-subtable">
          <div class="b-content"></div>
        </div>
      </td>
    </tr>
    <tr>
      <td class='m-bottom-cell'></td>
    </tr>
  </table>

.m-table {
  width: 100px;
  height: 250px;
  margin: 0 auto;
  position: relative;
  border-spacing: 0;
  padding: 0;

  border: 1px solid blue;
}

.m-top-cell {
  height: 100%;
  position: relative;

  background-color: red;
}

.m-bottom-cell {
  background-color: gold;
  height: 200px;
}

.b-subtable {
  background-color: #E76D13;
  border: 1px solid #E76D13;
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: 5px;
  right: 5px;
}

@-moz-document url-prefix() {
  .m-top-cell {
      padding: 5px;
  }

  .b-subtable {
    position: relative;
    display: table;
    height: 100%;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
  }

  .b-subtable:after {
    content: '. .';
    display: block;
    word-spacing: 99in;
    height: 0;
    overflow: hidden;

    font-size: 0.13em;
    line-height: 0;
  }
}

.b-content {
  background-color: orange;
  width: 15px;
  height: 15px;

  position: absolute;
  left: 10px;
  top: 10px;
}

最佳答案

这应该有效:

.m-top-cell{    
    /* other css properties */
    /*remove height:100% */ 
    position:relative;

}

.b-subtable{
    /* other css properties */
    /* remove height: 100% and display: table */
    position: absolute;
    top: 5px;
    bottom: 5px;
    left: 5px;
    right: 5px;
}

还要检查你的link标签符号,

<link rel="stylesheet" href="table.css" type="text/css" />

关于html - 如何在动态表格单元格中创建高度为 100% 的 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15685539/

相关文章:

php - 使用空格时图像 alt 和标题变得困惑

javascript - 使用 href 防止 VML 形状上的默认点击事件

html - CSS 背景图片在 IE 中不显示

php - 用于向 HTML 文档中的 .js 和 .css 引用添加版本号的正则表达式

html - <img> 元素中的背景图像

javascript - jQuery:根据所选选项显示/隐藏元素

php - html 表单预设值字段

css - 指针事件:没有在 IE 中不起作用

html - 使用负上边距覆盖页眉时背景隐藏

html - 在 angularjs 和 ionic-v1 中的一个公共(public)标题栏中只显示一个图标