【css】上下2个固定在视图中,中间自适应布局
2013-02-01 16:39
906 查看
有人想要个兼容布局:
View Code
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title></title>
<script type="text/javascript">
window.onscroll = window.onresize = window.onload =function (){
var div1 = document.getElementById('div1')
var div2 = document.getElementById('div2')
setScrollSize(div1, div2)
}
function setScrollSize(div1,div2){
var sHeight = document.documentElement.scrollTop || document.body.scrollTop;
var oHeight = document.documentElement.clientHeight || document.body.clientHeight;
oHeight += (sHeight -100); //这个100是他本身的高度
div1.style.top = sHeight + 'px';
div2.style.top = oHeight + 'px';
}
</script>
<style type="text/css">
html, body{position: relative; height: 100%;}
*{margin: 0; padding:0;}
#div1{position: absolute; top: 0; left: 0; background: red; height: 100px; width: 100%; z-index: 3}
#div2{position: absolute; bottom: 0; left: 0; background: red; height: 100px;width: 100%; z-index: 3}
#div3{position: absolute; top: 0; border: 1px solid #000; height:100%; width: 100%; z-index: 1; }
#div4{position: absolute; height: 100%; background: green; width: 100%; padding: 100px 0; height: 2000px; z-index: 1}
</style>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
<div id="div3">
<div id="div4">xdwadawdw</div>
</div>
</body>
</html>
window.onscorll滚动的时候不够平滑,可以考虑用缓冲运动。
View Code
<!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" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title></title> <script type="text/javascript"> window.onscroll = window.onresize = window.onload =function (){ var div1 = document.getElementById('div1') var div2 = document.getElementById('div2') setScrollSize(div1, div2) } function setScrollSize(div1,div2){ var sHeight = document.documentElement.scrollTop || document.body.scrollTop; var oHeight = document.documentElement.clientHeight || document.body.clientHeight; oHeight += (sHeight -100); //这个100是他本身的高度 div1.style.top = sHeight + 'px'; div2.style.top = oHeight + 'px'; } </script> <style type="text/css"> html, body{position: relative; height: 100%;} *{margin: 0; padding:0;} #div1{position: absolute; top: 0; left: 0; background: red; height: 100px; width: 100%; z-index: 3} #div2{position: absolute; bottom: 0; left: 0; background: red; height: 100px;width: 100%; z-index: 3} #div3{position: absolute; top: 0; border: 1px solid #000; height:100%; width: 100%; z-index: 1; } #div4{position: absolute; height: 100%; background: green; width: 100%; padding: 100px 0; height: 2000px; z-index: 1} </style> </head> <body> <div id="div1"></div> <div id="div2"></div> <div id="div3"> <div id="div4">xdwadawdw</div> </div> </body> </html>
<!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" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title></title>
<script type="text/javascript">
window.onscroll = window.onresize = window.onload =function (){
var div1 = document.getElementById('div1')
var div2 = document.getElementById('div2')
setScrollSize(div1, div2)
}
function setScrollSize(div1,div2){
var sHeight = document.documentElement.scrollTop || document.body.scrollTop;
var oHeight = document.documentElement.clientHeight || document.body.clientHeight;
oHeight += (sHeight -100); //这个100是他本身的高度
div1.style.top = sHeight + 'px';
div2.style.top = oHeight + 'px';
}
</script>
<style type="text/css">
html, body{position: relative; height: 100%;}
*{margin: 0; padding:0;}
#div1{position: absolute; top: 0; left: 0; background: red; height: 100px; width: 100%; z-index: 3}
#div2{position: absolute; bottom: 0; left: 0; background: red; height: 100px;width: 100%; z-index: 3}
#div3{position: absolute; top: 0; border: 1px solid #000; height:100%; width: 100%; z-index: 1; }
#div4{position: absolute; height: 100%; background: green; width: 100%; padding: 100px 0; height: 2000px; z-index: 1}
</style>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
<div id="div3">
<div id="div4">xdwadawdw</div>
</div>
</body>
</html>
window.onscorll滚动的时候不够平滑,可以考虑用缓冲运动。
相关文章推荐
- (div+css)上下固定中间自适应高度网页布局的实现(FF,IE)
- css布局(上下固定,中间自适应)
- CSS布局--上中下布局(上下固定,中间自适应)
- (div+css)上下固定中间自适应高度网页布局的实现
- (div+css)上下固定中间自适应高度网页布局的实现(FF,IE)
- CSS实现左右栏宽度固定中间栏宽度变化且各栏高度自适应背景色不同的三栏布局
- CSS---左右固定,中间自适应布局
- 使用CSS实现三栏自适应布局(两边宽度固定,中间自适应)
- 使用CSS实现三栏自适应布局(两边宽度固定,中间自适应)
- 记一道css面试题 : 三栏布局两边宽度固定,中间宽度自适应,并且布局随屏幕大小改变。
- CSS自适应布局(左右固定 中间自适应或者右侧固定 左侧自适应)
- 使用CSS实现三栏自适应布局(两边宽度固定,中间自适应)
- css经典布局——头尾固定高度中间高度自适应布局
- 网页上中下三分布局,上下固定,中间自适应
- css实现三列布局,左右固定值,中间自适应。
- 上下固定[不滚动]中间自适应高度布局
- CSS三列布局之左右宽度固定,中间元素自适应问题
- DIV+CSS经典??三列布局(左右固定 中间自适应)
- CSS自适应布局(左右固定 中间自适应或者右侧固定 左侧自适应)
- 网页上中下三分布局即上下固定中间自适应