兼容IE6的遮罩层

92 篇文章 0 订阅
51 篇文章 0 订阅

 

兼容IE6的遮罩层

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

蕃薯耀 2014年7月10日 18:06:35 星期四

 

兼容IE6的遮罩层,利用“* Html”这个Hack,设置IE6使用position:absolute;和 expression 来模拟fixed的效果,另外设置background:url(*)防止抖动。

 

遮罩层Css代码:

.overlay{
    position: fixed; 
    z-index: 100000; /*按需设置*/
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    filter: alpha(opacity=50);
    opacity: 0.5;
    overflow: hidden;
    background-color: #000;
	}
* html { background:url(*) fixed; }
* html body { margin:0; height:100%; }
* html .overlay{ 
   position: absolute; 
   left: expression(documentElement.scrollLeft + documentElement.clientWidth - this.offsetWidth); 
   top: expression(documentElement.scrollTop + documentElement.clientHeight - this.offsetHeight); 
}

 

屏幕居中代码:

.cen{
	 position:absolute;
    top:50%;
    left:50%;
    width:200px;
    height:100px;
    margin-top:-50px;
    margin-left:-100px;

    border:1px solid red;
    line-height:30px;
    font-size:16px;
    text-align:center;
    color: red;
}

 

 

完整示例代码:

<!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遮罩层 兼容IE6</title>
<script language="javascript" type="text/javascript">
function showdiv() {            
            document.getElementById("show").style.display ="block";
        }
function hidediv() {
            document.getElementById("show").style.display ='none';
        }
</script>
<style type="text/css">
 .overlay{
    position: fixed; 
    z-index: 100000; /*按需设置*/
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    filter: alpha(opacity=50);
    opacity: 0.5;
    overflow: hidden;
    background-color: #000;
	}
* html { background:url(*) fixed; }
* html body { margin:0; height:100%; }
* html .overlay{ 
   position: absolute; 
   left: expression(documentElement.scrollLeft + documentElement.clientWidth - this.offsetWidth); 
   top: expression(documentElement.scrollTop + documentElement.clientHeight - this.offsetHeight); 
}

.cen{
	 position:absolute;
    top:50%;
    left:50%;
    width:200px;
    height:100px;
    margin-top:-50px;
    margin-left:-100px;

    border:1px solid red;
    line-height:30px;
    font-size:16px;
    text-align:center;
    color: red;
}

</style>
</head>
<body>
<input id="btnshow" type="button" value="Show" οnclick="showdiv();"/>
<div id="show" class="overlay">
	<div class="cen">
		是否垂直居中?
		<input id="btnclose" type="button" value="Close" οnclick="hidediv();"/>
	</div>
</div>
</body>
</html>

 

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

蕃薯耀 2014年7月10日 18:06:35 星期四

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值