css - 位置固定的 DIV 滚动条部分隐藏在窗口滚动条后面

标签 css scrollbar fixed

我的页面中有一个目录(请参阅 here ),其中包含以下 CSS 样式:

div.toc {
    height:38em;
    position:fixed;
    right:0;
    top:5em;
    width:21em;
    z-index:1;
}

如何更改这些设置以确保 DIV 没有部分隐藏在正文/窗口滚动条后面?

(使用 Firefox 3.6 和 Opera 10.10 测试)。

最佳答案

实际上,您的 div.toc位置正确。问题出在您的 <iframe> .

记住你的盒子模型......宽度和高度是独立于边距和填充计算的......

W3C Box Model

因此,通过拥有 width: 100%;在您的 iframe.toc加一个 margin-left: 0.5em ,您基本上是在告诉浏览器以下内容:

Use the full width of the parent element and offset it 0.5em to the left.
Total effective width: 100% + 0.5em



你真正想说的是:

Substract 0.5em from the full width of the parent element to use as padding on the left and use this as width.
Total effective width: 100% - 0.5em (desired)



因此,解决方案很简单...删除 margin-left来自 iframe.toc并放一个 padding-left: 0.5emdiv.toc .
div.toc {
    background-color: #f0f0f0;
    position: fixed;
    top: 5em;
    right: 0;
    width: 21em;
    height: 38em;
    padding-left: .5em;
    border-left: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    border-top: 1px solid #ccc;
    z-index: 1;
}

iframe.toc {
    background-color: #f0f0f0;
    border: 0;
    width: 100%;
    height: 30em;
    border-bottom: 1px solid #ccc;
}

关于css - 位置固定的 DIV 滚动条部分隐藏在窗口滚动条后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2828914/

相关文章:

javascript - 如何删除以前边框的元素

html - 如何在保持绝对定位的同时使子div适合父div宽度?

python - 带有 tkinter 的很长的 list 框

javascript - 滚动条在 jquery 选项卡中不可见

CSS 3 动画固定位置侧边栏

javascript - 滚动时如何使 <div> 垂直相互删除?

css - Sifr3 - 是否可以使用父选择器覆盖 CSS 样式?

html - 底部栏 - 每个位置选项都会导致特殊问题

highcharts - 在 highcharts 中实现滚动条

css - 带有固定标题的 div 中的滚动条问题