CSS背景半透明

 如何做到CSS背景半透明呢,秘诀就是使用两层背景。

 底层是图片,上一层是一个透明度是0.5的黑色图层,就像加了滤镜一样。两层用z-index分辨。

代码如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
div{border:black solid thin;height:500px;width:300px;}
.back{background-image:url(myphoto.jpg);background-repeat:no-repeat;background-position:50% 50%;background-size: cover;z-index: -99}
.myba{background-color: rgba(0,0,0,0.5);z-index: -98}
.myba:hover{background-color: rgba(0,0,0,0.2);z-index: -96;border:white solid thin;font-size: 2em;}
p{font-family: myFirstFont;color: white;text-align:center;margin-top: 80px;}
p:hover{font-family: myFirstFont;color: white;text-align:center;margin-top: 80px;}
</style>
</head>
<body>
	<div class="back">
		<div  class="myba">
	<p>嘿嘿</p>
       </div>
   </div>
</body>	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值