z-index层叠

如果定位元素的层级一样,下面得元素会覆盖住上面的元素
可以使用z-index设置定位元素
一个元素可以有正数或负数得堆叠顺序,数字越大,层级越高
对于没有使用定位的元素不能使用z-index属性*/
opacity: 0.5;
opacity:可以设置元素背景的透明度
它的值只能是在0-1之间
0:代表完全透明
1:代表完全不透明
0.5:代表半透明

			 IE8及一下浏览器不支持opacity
			 IE8以及更早的版本支持替代的filter属性
			 例如:filter:Alpha(opacity=透明度)。
			 透明度值在0-100之间
			 0:完全透明
			 50:半透明
			 100:不透明

父元素的层级再高,也盖不住子元素
小例子:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>z-index</title>
		<style>
			.c1{
				width: 200px;
				height: 200px;
				background-color: #0000FF;
				position: relative;
				z-index: 999;
				
				opacity: 0.5;
			
				filter: Alpha(opacity=50);
			}
			.c2{
				width: 200px;
				height: 200px;
				background-color: red;
				position: absolute;
				left: 100px;
				top: 100px;
				z-index: 99;
				opacity: 0.5;
			}
			.c3{
				width: 200px;
				height: 200px;
				background-color: yellowgreen;
				position: absolute;
				left: 200px;
				top: 200px;
				z-index: 9;
				opacity: 0.5;
			}
			.c4{
				width: 200px;
				height: 200px;
				background-color: #518700;
				/*相对定位*/
				position: relative;
				top: 400px;
				z-index: 9999;
				
			}
			.c5{
				width: 100px;
				height: 100px;
				background-color: #800080;
				position: relative;
				z-index: 99;
			}
		</style>
	</head>
	<body>
		<div class="c1"></div>
		<div class="c2"></div>
		<div class="c3"></div>
		<div class="c4">
			<div class="c5"></div>
		</div>
	</body>
</html>

图片

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值