div+css遮罩层

时间:2023-07-17 08:28:32

曾被问到这个问题,不知所措,后来在网上找到了.大神文章:http://www.cnblogs.com/aspx-net/archive/2011/03/11/1981071.html

我想实现的效果没有上面那么多,仅仅出现一个灰蒙蒙的div层就可以了,所以做了一些改动.

 <!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">
<head>
<title>DIV CSS遮罩层</title>
<script language="javascript" type="text/javascript">
function showdiv() {
document.getElementById("bg").style.display = "block";
}
function hidediv() {
document.getElementById("bg").style.display = 'none';
}
</script>
<style type="text/css">
#bg{ display: none;
position: absolute;
top: 10%;
left: 10%;
width: 80%;
height: 80%;
background-color: grey;
z-index:1;
-moz-opacity: 0.7; /*不知道有啥用*/
opacity:0.70; /*不知道有啥用*/
filter: alpha(opacity=10); /*这个是真正起作用的*/
}
</style>
</head>
<body>
<input id="btnshow" type="button" value="Show" onclick="showdiv();"/><br/><br/>
<input id="btnclose" type="button" value="Close" onclick="hidediv();"/>
<div id="bg"></div>
</body>
</html>