css中z-index属性

发布日期:2023-05-26 浏览次数:3

1、z-index属性值:当默认值为0时,z-index属性可以设置各元素之间的重叠关系。

2、z-index值大的层位于其值小的层之上。

css z-index实例

div {
     position: relative;
     width: 100px;
     height: 100px;
}
 p {
     position: absolute;
     font-size: 20px;
     width: 100px;
     height: 100px;
}
 .a {
     background-color: pink;
     z-index: 1;
}
 .c {
     background-color: green;
     z-index: 2;
     top: 20px;
     left: 20px;
}
 .b {
     background-color: red;
     z-index: 3;
     top: -20px;
     left: 40px;
}
如果您有什么问题,欢迎咨询技术员 在线沟通