博主信息
博文 15
粉丝 0
评论 0
访问量 12868
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
绝对定位之遮罩219.1.15
ken的博客
原创
816人浏览过

学习了遮罩之后,我自己也稍微修好了下正常页面下大致的适用场景:

实例

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="css/style4.css">
	<title>绝对定位之遮罩</title>
	<style type="text/css">
*{
	margin:0px;
	padding:0px;
}
.clear{clear: both;}
/*头部header*/
.header{
	height: 50px;
	width: 100%;
	background:pink;
}
.header .nav{
	height: 50px;
	width: 1200px;
	margin: 0px auto;
	background:pink;

}
 .header_right {
	height: 50px;
	width: 180px;
	text-align: center;
    float: right;
    line-height: 50px;

}

.nav a{
	text-decoration: none;
	color: #fff;
	margin-right:15px;
	padding: 15px;
	font-size: 16px;
}
.nav a:hover{
	background-color:#ccc;
	color: #000; }
ul li{
	height: 50px;
	list-style: none;
	float: left;
	line-height: 50px;
}

/*主体部分main*/
.container{
	width: 1200px;
	height: 600px;
	margin:5px auto;
	background-color: #ccc;

}
.wrap{
	width: inherit;
	min-height: 600px;
	background-color: blue;
	float: left;
}
.main{
	padding-left: 200px;
	padding-right: 200px;
}

.left{
	width: 200px;
	min-height: 600px;
	background-color: yellow;
	float: left;
	margin-left: -100%;
}
.right{
	width: 200px;
	min-height: 600px;
	background-color: pink;
	float: left;
	margin-left:-200px;
}

/*底部footer*/
.footer{height: 200px;
	width: 100%;
	background-color: #000;}
.footer_content{
	width: 1200px;
	height: 200px;
	margin:0px auto;
	
	background-color: #000;
}
.footer_left{
	width: 600px;
	height: 200px;
}
.footer_left a{
	text-decoration: none;
	color: #ccc;
	font-size: 13px;
	margin-right: 5px;
	
}
.footer_left a:hover{
	color: #fff;
}
.footer_left p{color: #ccc; font-size: 13px;float: left;}

/*绝对定位遮罩,使用绝对定位文本将不在文本流中*/

#shade{
	width:100%;
	height:100%;
	background-color:#000;
	position: absolute;
	z-index: 100;
	opacity: 0.6;
	display: none;
}
#login{
	width: 300px;
	height: 250px;
	position: absolute;
	background-color: yellow;
    z-index: 101;
    left:50%;
    top:50%;
    margin-left:-150px;
    margin-top: -125px;
    display: none;
}

	</style>
		<script>
	function open(){
		var bg = document.getElementById('shade');
		bg.style.display = 'block';
		var lg = document.getElementById('login');
		lg.style.display = 'block';
	}
	function close(){
		var bg = document.getElementById('shade');
		bg.style.display = 'none';
		var lg = document.getElementById('login');
		lg.style.display = 'none';

	}
	</script>

</head>
<body>
	<div id="shade"></div>
	<div id="login"><a href="javascript:close()">关闭</a><p>我是一个遮罩</p></div> 
<div class="header">
 
	<div class="nav">
		<ul>
			<li><a href="">首页</a></li>
			<li><a href="">视频教程</a></li>
			<li><a href="">社区问答</a></li>
			<li><a href="">编程词典</a></li>
			<li><a href="">手册下载</a></li>
			<li><a href="">工具下载</a></li>
			<li><a href="">特色课程</a></li>
			<li><a href="">菜鸟课堂</a></li>
		</ul>
<div class="header_right">
 	<a href="javascript:open()">登录</a>
 	<a href="">注册</a>
 </div>
	</div>

<div class="clear"></div>
</div>

<div class="container">
	<div class="wrap">
		<div class="main">主体部分</div>
	</div>

	<div class="left">
		左边
	</div>

	<div class="right">
		右边
	</div>
</div>

<div class="footer">
	<div class="footer_content">
		<div class="footer_left">
		<ul>
			<li><a href="">首页</a></li>
			<li><a href="">视频教程</a></li>
			<li><a href="">社区问答</a></li>
			<li><a href="">编程词典</a></li>
			<li><a href="">手册下载</a></li>
			<li><a href="">工具下载</a></li>
			<li><a href="">特色课程</a></li>
			<li><a href="">菜鸟课堂</a></li>
		</ul>
		<p>PHP中文网:独家原创,永久免费的在线php视频教程,php技术学习阵地!</p>
		<p>Copyright 2014-2018 http://www.php.cn/ All Rights Reserved | 皖B2-20150071-9</p>
		</div>
	</div>

</div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

总结

  1. 遮罩功能和JS关闭登入结合了下,大致做了一个,不是很好。

  2. 遮罩主要就是使用绝对定位做,需要注意的是居中后,要margin上左才会居中。

  3. 这个遮罩出现滚动时是不会跟屏幕一起移动的,还是需要position:fixed;加个固定定位应该就可以实现。

批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学