css - 溢出 :scroll not working for div containing table in ie and ff

标签 css

我有一个 div,它应该是基于百分比的高度。它包含一个表格,当窗口太短时,div 应该有一个滚动条来查看表格的内容。它在 Chrome 中看起来正确,但在 IE 和 FF 中,div 的最小高度是它包含的表格的高度。

这是一个 jsfiddle: http://jsfiddle.net/Y8Xyb/

这是 html:

<div class="outerDiv">
    <table class="outerTable">
        <tr>
            <td class="header">Title
                <table class="innerTable">
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                    <tr>
                        <td class="data">User info</td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</div>

这是CSS:

 .outerDiv{
   border: thin solid black;
   height:90%;
   overflow:scroll;
 }

为了回应下面发帖的人,即使在添加之后

html,正文{ 高度:100%;

div 在 IE 和 FF 中仍然占据表格的整个高度。

最佳答案

这是一个经典问题 - 高度基本上是文档的 90%,并且文档比窗口高。此解决方案通常有效 - 将文档设置为窗口的高度 see it working on JSFiddle :

html, body {
    height: 100%;
    margin: 0;
}

 .outerDiv{
    border: thin solid black;
    height: 90%;
    overflow: auto;
}

关于css - 溢出 :scroll not working for div containing table in ie and ff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22667278/

相关文章:

css - 动态CSS布局

css - 如何使我的 &lt;input type ="submit"/> 成为图像?

css - 如何在某种图片库中对齐 ul 中包含的图像

javascript - 具有单个描述字段的图像网格,可在单击时更改

css - 垂直对齐 div 内的列表项

jquery - 添加第二个菜单时无法单击菜单上的元素

html - 悬停不使用 Font Awesome 图标

html - 如何更改django中的默认注册

javascript - AngularJS - ng-style 不更新 css 背景属性

css - 在按钮中的 Font Awesome 顶部添加图标?