在IE 6及更高版本中,CSS框架布局无法正常工作

时间:2010-11-17 03:04:06

标签: css internet-explorer scroll positioning frames

我正在尝试使用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>

1 个答案:

答案 0 :(得分:0)

你需要在#maincontent和#framecontent div上设置高度,否则它们永远不会滚动,它们只会伸展以适合它们的内容。 %高度可能会给IE带来麻烦,并且可能会导致意外结果(以我简陋的经验)。您是否尝试过仅移除IE?

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