原文:https://www.cnblogs.com/zouqin/p/5498495.html
問題: 怎麼實現 父元素的背景覆蓋子元素的背景呢?
————————————————————————————
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> .test1{ width: 100px; height: 100px; border: 1px solid green; background: green; position: absolute; z-index: auto; } .test2{ width: 100px; height: 100px; border: 1px solid black; background: black; position: relative; left: 20px; top: -20px; z-index: -1; } </style> </head> <body> <div class="test1"> <div class="test2"></div> </div> </body> </html>
父元素不設置z-index 的值時,默認是auto。此時在設置子元素的值爲負數
瞭解一下,同一個“堆疊上下文中,元素的堆疊順序”??