首页 > 文章列表 > css中z-index属性

css中z-index属性

css z-index
220 2022-08-06

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

2、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;  
        }

本文教程操作环境:windows7系统、css3版,DELL G3电脑。