h5--------------层级

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>

<style type="text/css">

.box1{
width: 200px;
height: 200px;
background-color: red;
position: relative;

z-index: 2;

opacity: 0.5;
filter: alpha(opacity=50);
}
.box2{
width: 200px;
height: 200px;
background-color: yellow;
/*开启绝对定位*/
position: absolute;
/*设置偏移量*/
top: 100px;
left: 100px;
/*
* 如果定位元素的层级是一样,则下边的元素会盖住上边的
* 通过z-index属性可以用来设置元素的层级
* 可以为z-index指定一个正整数作为值,该值将会作为当前元素的层级
* 层级越高,越优先显示

* 对于没有开启定位的元素不能使用z-index
*/
z-index: 25;

opacity: 0.5;
filter: alpha(opacity=50);

}
.box3{
width: 200px;
height: 200px;
background-color: yellowgreen;
/*position: relative;
z-index: 3;*/
position: absolute;
top: 200px;
left: 200px;
z-index: 30;

/*
* 设置元素的透明背景
* opacity可以用来设置元素背景的透明,
* 它需要一个0-1之间的值
* 0 表示完全透明
* 1 表示完全不透明
* 0.5 表示半透明
*/
opacity: 0.5;

/*
* opacity属性在IE8及以下的浏览器中不支持
* IE8及以下的浏览器需要使用如下属性代替
* alpha(opacity=透明度)
* 透明度,需要一个0-100之间的值
* 0 表示完全透明
* 100 表示完全不透明
* 50 半透明

* 这种方式支持IE6,但是这种效果在IE Tester中无法测试
*/
filter: alpha(opacity=50);
}

.box4{
width: 200px;
height: 200px;
background-color: orange;
/*开启相对定位*/
position: relative;
/*
* 父元素的层级再高,也不会盖住子元素
*/
z-index: 20;

top: 500px;
}

.box5{
width: 100px;
height: 100px;
background-color: skyblue;
/*开启绝对定位*/
position: absolute;
z-index: 10;
}

</style>

</head>
<body style="height: 5000px;">

<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4">
<div class="box5"></div>
</div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值