在页面中,经常会遇到这样的效果,一个图层总是在某一个位置,无论滚动条滚动与否,这个Div始终都在这个位置显示。刚开始以为是用js实现的,确实,可以利用js去实现,但是在css中有更好的方法。利用position属性fixed,来实现Div相对于整个窗体的定位。
下面是菜鸟代码,如果有更好的方法欢迎交流分享,也希望大神们可以对我的代码提出宝贵意见。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
<meta name="author" content="Administrator" />
<!-- Date: 2014-08-04 -->
<style type="text/css">
body {margin:0;padding:0;}
.container01{width:1002px;height:50px;background:#59A725;position:fixed;
left:50%;margin-left:-501px;text-align:center;line-height:50px;}
.container{margin: 0 auto;width: 1002px;height:1200px;padding-top:50px;
background:#666600;}
</style>
</head>
<body>
<div class="container01">固定图层</div>
<div class="container">
123
</div>
</body>
</html>
资源免费下载地址:http://download.csdn.net/detail/u014703834/7711777