css - 没有 Javascript 的固定 100% div 内的滚动条

标签 css html scrollbar

好的,所以我在屏幕右侧有一个固定的 div,它是 window 的高度。当内容超出 div 的空间时,我希望 divscrollbar 溢出。

我已经在 Chrome 中做到了这一点,但它在 Firefox 中不起作用。

SSCCE

HTML:

<div id="outer">
    <div id="middle">
        <div id="inner">
        </div>    
    </div>
</div>

CSS:

div#outer{
    position    : fixed;
    top         : 0;
    right       : 0;
    display     : table;
    z-index     : 200;
    width       : 320px;
    height      : 100%;
}

div#middle {
    display     : table-cell !important;
    max-width   : 300px;
max-height  : 100%;
}

div#inner {
    overflow-y: auto;
    height: 100%;
}

为什么不起作用?我该怎么做才能修复它?

我知道我可以将事件绑定(bind)到窗口调整大小并强制设置 div 高度,但我更喜欢 CSS 解决方案。

最佳答案

用 overflow:auto 制作容器;绝对。 http://jsfiddle.net/NicoO/49SY8/

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

div#outer{
    position    : fixed;
    top         : 0;
    right       : 0;
    z-index     : 200;
    width       : 320px;
    height      : 100%;
}

div#middle {
    max-width   : 300px;
}

div#inner {
    overflow: auto;
    position: absolute;
    bottom:0;
    left:0;
    right:0;
    top:0;
}

关于css - 没有 Javascript 的固定 100% div 内的滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22156989/

相关文章:

html - CSS:将高度对齐的按钮附加到输入

javascript - 使用 jquery 制作图像 slider

html - 我如何使所有内部 div 填充其父 div 的整个高度?

javascript - JS - 水平滚动

javascript - 在 CODEPEN 上使用已编译或未编译的 css 来重新创建动画?

css - Spring MVC 4 + Thymeleaf : static resources 404 error

jquery - 有什么方法可以证明单段落行的合理性吗?

css - 仅使用 CSS 的最大高度和最大宽度

python - wxpython 中静态文本的滚动条?

WPF DataGrid 不会在拖动时滚动