博客列表 >绝对定位之遮罩219.1.15

绝对定位之遮罩219.1.15

ken的博客
ken的博客原创
2019年01月22日 09:08:29645浏览

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

实例

<!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 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议