【问题标题】:Issue to scroll tbody on IE 9 (tbody's height = height-line)在 IE9 上滚动 tbody 的问题(tbody 高度 = 高度线)
【发布时间】:2012-10-01 22:42:08
【问题描述】:

对不起,我的英语不好,我希望你能明白我想说的话......

我正在尝试实现一个 HTML 表格,它支持独立于表格头部滚动表格主体。

我发现以下问题对我有很大帮助: How to scroll table's "tbody" independent of "thead"?

我测试了以下代码,它可以在 Chrome (22)、Firefox (16) 和 Opera (12) 上正常运行:

HTML:

<table>
  <thead>
   <tr>
    <th>Title1</th>
    <th>Title2</th>
    <!-- ... -->
   </tr>
  </thead>
  <tbody>
   <tr>
     <td>...</td>
     <td>...</td>
     <!-- ... -->
   </tr>
   <!-- ... -->
  </tbody>
</table>

CSS:

thead, tbody {
    display: block;
}

tbody {
    height:500px;
    overflow-y:auto;
    overflow-x:hidden;
}

thead {
    line-height: 20px;
}

所以它可以在除 IE 9 之外的主要浏览器上运行,在 IE 上,我有一些问题:

  • tbody 的高度未定义(所以我没有任何滚动条)
  • 每个都有 500px 的高度(其他浏览器上 tbody 的高度)

以下两个示例具有完全相同的问题:http://jsfiddle.net/nyCKE/2/http://www.imaputz.com/cssStuff/bigFourVersion.html

我看到了以下问题(和答案),但对我没有帮助:IE9 + css : problem with fixed header table

所以我确定这个错误来自 IE,但我不知道如何在不改变我的 HTML 结构的情况下修复它。

有人知道吗?

【问题讨论】:

    标签: html css scroll html-table internet-explorer-9


    【解决方案1】:

    我稍微尝试过修复它。希望能给个思路

    HTML

    <div class="wrap">
        <div class="inner">
            <table>
                <thead><tr>
                    <th><p>Problem</p></th>
                    <th><p>Solution</p></th>
            </tr>               
                </thead>            
                <tbody>              
                </tbody>
            </table>
        </div>
    </div>​
    

    CSS

    p {margin:0 0 1em}
    table p {margin :0}
    .wrap {
        margin:50px 0 0 2%;
        float:left;
        position:relative;
        height:200px;
        overflow:hidden;
        padding:25px 0 0;
        border:1px solid #000;
    width:150px
    }
    .inner {
        padding:0 ; 
        height:200px;
        overflow:auto;
    }    
    table {  margin:0 0 0 -1px; border-collapse:collapse; width:130px}
    td {
        padding:5px;
        border:1px solid #000;
        text-align:center;    
    }
    thead th {
        font-weight:bold;
        text-align:center;
        border:1px solid #000;
        padding:0 ;    
        color:#000;
    }
    thead th {border:none;}
    thead tr p {  position:absolute;   top:0;    }
    .last { padding-right:15px!important; }​
    

    演示http://jsfiddle.net/nyCKE/272/

    【讨论】:

    • 谢谢!它有效,只有一个问题。使用该解决方案,当我们滚动时,只有&lt;th&gt; 上的&lt;p&gt; 可见。但是我也必须看到我的&lt;th&gt; 的样式(因为我使用tableSorter 插件),所以我将absolute 值直接放在我的&lt;th&gt; 上,并使用jQuery 设置我的left CSS 属性功能。它并不完美(因为它使用 Javascript,而且我认为没有 border-collapse:collapse 就无法工作),但它可以在 IE 上运行,我希望这个 bug 会尽快修复。
    【解决方案2】:

    这是一个简短的答案,允许您在 ie9 中滚动带有固定标题的表格。

    在表格周围添加条件 div

    <!--[if lte IE 9]>
    <div class="old_ie_wrapper">
    <!--<![endif]-->
    <table>
    ...
    <!--[if lte IE 9]>
    </div>
    <!--<![endif]-->
    

    为ie9添加以下样式

        .old_ie_wrapper {
            height: 500px;
            overflow: auto;
        }
    
            .old_ie_wrapper tbody {
                height: auto;
            }
    
            .old_ie_wrapper thead tr {
                position: absolute;
            }
    
            .old_ie_wrapper tbody tr:first-child {
                height: 67px;
                vertical-align: bottom;
            }
    

    您将不得不根据您的表格调整高度和可能的其他属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-17
      • 1970-01-01
      • 2014-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-17
      相关资源
      最近更新 更多