z-index

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>z-index</title>
<style type="text/css">
.box {
/*辅助子级进行绝对定位*/
position: relative;
width: 400px;
height: 400px;
background-color: red;
margin: 0 auto;
}
.d1, .d2, .d3 {
width: 200px;
height: 200px;
position: absolute;
}
.d1 {
background-color: orange;
}
.d2 {
background-color: blue;
top: calc(50% - 100px);
left: calc(50% - 100px);
}
.d3 {
background-color: black;
right: 0;
bottom: 0;
}
/*脱离文档流的标签,具有z-index属性,可以用来控制显示层次的优先级,值为任意正整数*/
.d2 {
z-index: 88888
}
.d3 {
z-index: 666
}
</style>
</head>
<body>
<!-- 需求1:d1,d2,d3均为box的一半大小 -->
<!-- 需求2:d1左上角,d2居中,d3右下角 -->
<!-- 需求3:d2区域在最上方(会覆盖d1,d3的重叠部分) -->
<div class="box">
<div class="d1"></div>
<div class="d2"></div>
<div class="d3"></div>
</div>
</body>
</html>

posted @ 2018-09-27 14:51  不沉之月  阅读(92)  评论(0编辑  收藏  举报