【问题标题】:How to create div with 100% height in dynamic table-cell?如何在动态表格单元格中创建 100% 高度的 div?
【发布时间】:2013-03-19 02:37:37
【问题描述】:

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

我有最小的解决方案 - 这仅适用于 Chrome 和 Firefox。在 Opera 和 IE 中,子 div 具有顶部表格大小。没有js的opera和ie有解决办法吗?

好:

不好:


更新 #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;
}

【问题讨论】:

  • “在 Opera 和 IE 中,子 div 具有顶部表格大小”是什么意思。 ?
  • 您是否有理由必须使用表格单元格?不建议将表格用于布局,而且通常我只是将 div 用于表格结构。你描述的场景是什么?另外,我对您所说的“在 Opera 和 IE 中子 div 具有顶部表格大小”的意思感到困惑
  • @GrahamRobertson 有 3 个表格单元格,位于列中。单元的顶部和底部具有固定的尺寸并固定在单元的顶部和底部。中心单元是无量纲的。它里面是一个更大的块,但大小不应该被认为是一个单元格。

标签: html css internet-explorer html-table opera


【解决方案1】:

这应该可行:

.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" />

【讨论】:

  • 在 HTML5 中 type="text/css" 是默认值。没有必要写。您的解决方案在 FF 和 IE 中不起作用 - position:relative; for table-cell 不起作用。
  • @ReklatsMasters 您是否按照我在帖子中的建议删除了height:100% 和其他属性?
猜你喜欢
  • 2016-12-14
  • 2017-12-24
  • 2016-11-09
  • 1970-01-01
  • 2012-04-14
  • 1970-01-01
  • 2013-01-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多