CSS Frames 让我们彻底抛弃FRAMESET吧

       开发项目时候,我们经常要用到FRAMSET或者IFrame来做一些框架的页面,FRAMESET可以自适应高度以及宽度,但是在FRAMESET各页面之间跨越执行JS时候即麻烦又会时不时的出一些莫名其妙的错误,而使用IFRAME,如果想使用DIV+CSS的方式来布局,目前至少我暂时无法通过CSS来完美实现了IFRAME的高度自适应问题,必须来借助JS来实现,突然间,某天浏览http://www.dynamicdrive.com/style时候发现了CSS FRAME,先不研究,上图上代码:
网站原内容

CSS Frames Layouts

New (Dec 26th, 06'): The following are a collection of CSS Frames layouts, where select columns or rows inside the layout remain static even when the page is scrolled, mimicking a frames like behavior.

CSS Left Frame Layout
This is a two columns liquid layout with the left column being static, always in view.
CSS Right Frame Layout
This is a two columns liquid layout with the right column being static, always in view.
CSS Top Frame Layout
This is a two rows liquid layout with the top row being static, always in view.
CSS Bottom Frame Layout
This is a two rows liquid layout with the bottom row being static, always in view.
CSS Left and Right Frames Layout
This is a three columns liquid layout with the leftmost and rightmost columns being static, always in view.
CSS Left and Top Frames Layout
This is a mixed columns and rows layout (two main columns, later split into two rows), with the leftmost column and top row being static, always in view.
CSS Left and Bottom Frames Layout
This is a mixed columns and rows layout (two main columns, later split into two rows), with the leftmost column and bottom row being static, always in view.
CSS Top and Bottom Frames Layout
This is a three rows liquid layout with both the top and bottom rows being static, always in view.
CSS Left, Top and Right Frames Layout
This is a mixed columns and rows layout (three main columns, middle column split into two rows), with everything being static except the bottom row in the middle column.
CSS Left, Bottom and Right Frames Layout
This is a mixed columns and rows layout (three main columns, middle column split into two rows), with everything being static except the top row inside the middle column.
CSS Left, Top and Bottom Frames Layout
This is a mixed columns and rows layout (two main columns, later split into three rows), with everything being static except the center row in the right column.
CSS Left, Top, Bottom and Right Frames Layout
This is a mixed columns and rows layout (three main columns, middle column split into three rows), with all of the surrounding columns and rows being static, except the very center container.


下面就先挑几种我认为有价值的页面附下源码:

一:CSS Top Frame (价值:top使用固定像素时,解决了FRAME的高度自适应问题)



<!--Force IE6 into quirks mode with this comment tag-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Dynamic Drive: CSS Top Frame Layout</title>
<style type="text/css">

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

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


#maincontent
{
position
: fixed; 
top
: 130px; /*Set top value to HeightOfFrameDiv*/
left
: 0;
right
: 0;
bottom
: 0;
overflow
: auto; 
background
: #fff;
}

.innertube
{
margin
: 15px; /*Margins for inner DIV inside each DIV (to provide padding)*/
}

* html body
{ /*IE6 hack*/
padding
: 130px 0 0 0; /*Set value to (HeightOfFrameDiv 0 0 0)*/
}

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

</style>

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

</head>

<body>

<div id="framecontent">
<div class="innertube">

<h1>CSS Top Frame Layout</h1>
<h3>Sample text here</h3>

</div>
</div>


<div id="maincontent">
<div class="innertube">

<h1>Dynamic Drive CSS Library</h1>
<p><script type="text/javascript">filltext(255)</script></p>

<style="text-align: center">Credits: <href="http://www.dynamicdrive.com/style/">Dynamic Drive CSS Library</a></p>

</div>
</div>


</body>
</html>

二:CSS Left and Top Frames (最常见也使用最多的框架布局)



<!--Force IE6 into quirks mode with this comment tag-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Dynamic Drive: CSS Left and Top Frames Layout</title>
<style type="text/css">

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

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

#framecontentTop
{ 
left
: 200px; /*Set left value to WidthOfLeftFrameDiv*/
right
: 0;
width
: auto;
height
: 120px; /*Height of top frame div*/
overflow
: hidden; /*Disable scrollbars. Set to "scroll" to enable*/
background-color
: navy;
color
: white;
}

#maincontent
{
position
: fixed; 
left
: 200px; /*Set left value to WidthOfLeftFrameDiv*/
top
: 120px; /*Set top value to HeightOfTopFrameDiv*/
right
: 0;
bottom
: 0;
overflow
: auto; 
background
: #fff;
}

.innertube
{
margin
: 15px; /*Margins for inner DIV inside each DIV (to provide padding)*/
}

* html body
{ /*IE6 hack*/
padding
: 120px 0 0 200px; /*Set value to (HeightOfTopFrameDiv 0 0 WidthOfLeftFrameDiv)*/
}

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

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

</style>

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

</head>

<body>

<div id="framecontentLeft">
<div class="innertube">

<h3>Sample text here</h3>

</div>
</div>

<div id="framecontentTop">
<div class="innertube">

<h1>CSS Left and Top Frames Layout</h1>
<h3>Sample text here</h3>

</div>
</div>


<div id="maincontent">
<div class="innertube">

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

</div>
</div>


</body>
</html>

其他的就先不附源码了,大家可以在这里下载https://files.cnblogs.com/aaa/css%20frame.rar

当然,以上的这些CSS frame 都是在单页面的情况下实现框架的,您也可以在框架的DIV内放一个高宽都是100%的IFRAME来实现嵌入页面,主要不要使用CSS来规定高宽100%,用IRAME自身的属性。

当你加入IRAME,或者您又在VS2005中编辑站点,你可能又会发现存在一些问题,例如滚动条在不同浏览器下出现移位,那么只需要在页面顶部加入下面代码即可解决:

<?xml version="1.0" encoding="UTF-8"?>

但引入此代码可能会造成IE下某些CSS样式的BUG,所以大家均衡着使用吧,或者有完美解决方案大家可以讨论下。

水平有限,第一次写博,难免疏漏,见谅。
posted @ 2008-04-02 10:00  西安小柯  阅读(9847)  评论(3编辑  收藏  举报