css父元素背景覆蓋其子元素背景


 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6         <style>
 7             
 8             .test1{
 9                 width: 100px;
10                 height: 100px;
11                 border: 1px solid green;
12                 background: green;
13                 position: absolute;
14                 z-index: auto;
15             }
16             
17             .test2{
18                 width: 100px;
19                 height: 100px;
20                 border: 1px solid black;
21                 background: black;
22                 position: relative;
23                 left: 20px;
24                 top: -20px;
25                 z-index: -1;
26             }
27         </style>
28     </head>
29     <body>
30         <div class="test1">
31             <div class="test2"></div>
32             
33         </div>
34         
35     </body>
36 </html>

父元素不設置z-index 的值時,默認是auto。此時在設置子元素的值為負數


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM