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

发布于 2024-10-03 01:32:38 字数 2452 浏览 10 评论 0原文

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

I am trying to make a CSS page layout using DIVs to emulate frames.

I want a fixed top pane that has a fixed height and the width stretches and shrinks as the page is resized. (fixed meaning if the user scrolls down the page, the top pane is always visible)

Below that I want two columns. The left column has a fixed width and the right column stretches in width as you resize the window. Both columns should have vertical scrollbars when necessary.

My code seems to work fine in Chrome, but in IE, the scrollbars don't show up in the left or the right columns.

Is there something I can do to fix this? Maybe some javascript to tell IE to draw the scrollbars properly?

style:

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:

<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 body:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

标点 2024-10-10 01:32:38

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

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

You need to set heights on the #maincontent and #framecontent divs or they will never scroll, they will just stretch to fit their contents. The % height may cause trouble for IE, and it can cause unexpected results (in my humble experience). Have you tried removing the IE only CSS?

Also, to correct a comment in your CSS, overflow: auto doesn't disable scrollbars. It hides them when they aren't needed and shows them when they are.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文