【问题标题】:css frame layout isn't working properly in IE 6 and abovecss 框架布局在 IE 6 及更高版本中无法正常工作
【发布时间】:2010-11-17 03:04:05
【问题描述】:

我正在尝试使用 DIV 模拟框架来制作 CSS 页面布局。

我想要一个固定的顶部窗格,它具有固定的高度,并且宽度会随着页面大小的调整而伸​​缩。 (固定含义如果用户向下滚动页面,顶部窗格始终可见)

下面我想要两列。当您调整窗口大小时,左栏的宽度固定,右栏的宽度会延伸。必要时两列都应该有垂直滚动条。

我的代码在 Chrome 中似乎可以正常工作,但在 IE 中,滚动条不显示在左侧或右侧列中。

我可以做些什么来解决这个问题吗?也许一些 javascript 告诉 IE 正确绘制滚动条?

风格:

body{
    margin: 0px;
    padding: 0px;
    border: 0px;
    overflow: hidden;
    height: 100%; 
    max-height: 100%; 
}

#framecontentTop{
    position: absolute;
    top: 0px; 
    left: 0px; 
    width: 100%; 
    height: 108px; /*Height of frame div*/
    overflow: hidden; /*Disable scrollbars. Set to "scroll" to enable*/
    background-color: navy;
    color: white;
}

#framecontent{
    position: absolute;
    top: 108px;
    left: 0px;
    bottom: 0px;    
    width: 200px; /*Width of frame div*/
    float:right;
    overflow: auto; /*Disable scrollbars. Set to "scroll" to enable*/
    background: navy;
    color: white;
    /*padding: 108px 0 0 200px; */ /*Set value to (0 0 0 WidthOfFrameDiv)*/
}


#maincontent{
    position: absolute;
    top: 108px; 
    left: 200px; /*Set left value to WidthOfFrameDiv*/
    right: 0px;
    bottom: 0px;
    float:right;
    overflow: auto; 
    background: #fff;
}


* html body { /*IE6 hack*/

}


* html #maincontent{ /*IE6 hack*/
    height: 100%; 
    width: 100%; 
}

脚本:

<script type="text/javascript">
/*** Temporary text filler function. Remove when deploying template. ***/
var gibberish=["This is just some filler text", "Welcome to Dynamic Drive CSS Library", "Demo content nothing to read here"]
function filltext(words){
for (var i=0; i<words; i++)
document.write(gibberish[Math.floor(Math.random()*3)]+" ")
}
</script>

html 正文:

<div id="framecontentTop">
<h1>CSS Top Frame Layout</h1>
<h3>Sample text here</h3>
</div>


<div id="framecontent">
<h1>CSS Left Frame Layout</h1>
<p><script type="text/javascript">filltext(25)</script></p>
</div>


<div id="maincontent">
<h1>Dynamic Drive CSS Library</h1>
<p><script type="text/javascript">filltext(255)</script></p>
<p style="text-align: center">Credits: <a href="http://www.dynamicdrive.com/style/">Dynamic Drive CSS Library</a></p>
</div>


</body>
</html>

【问题讨论】:

  • 请重新格式化您问题中的代码,输入框下方的框(textarea),您可以在提交之前预览您的帖子。

标签: css internet-explorer scroll positioning frames


【解决方案1】:

您需要在#maincontent 和#framecontent div 上设置高度,否则它们将永远不会滚动,它们只会拉伸以适应其内容。 % 高度可能会给 IE 带来麻烦,并且可能会导致意想不到的结果(以我的拙见)。您是否尝试过删除仅 IE 的 CSS?

此外,要更正 CSS 中的注释,overflow: auto 不会禁用滚动条。它会在不需要时隐藏它们,并在需要时显示它们。

【讨论】:

    猜你喜欢
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-11
    • 2012-06-19
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    相关资源
    最近更新 更多