Div+Css实现图层固定,吊窗

      在页面中,经常会遇到这样的效果,一个图层总是在某一个位置,无论滚动条滚动与否,这个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
发布了35 篇原创文章 · 获赞 7 · 访问量 7万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章