1.z-indexhtml
(1)z軸。數值越大,越靠近你spa
(2)只能做用於定位過的標籤元素code
應用示例htm
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>05丐版模特框</title> <style> .cover { position: absolute; /* 絕對定位 */ top: 0; right: 0; bottom: 0; left: 0; background-color: rgba(0, 0, 0, 0.5); z-index: 999; } .modal { width: 600px; height: 400px; background-color: white; position: fixed; top: 50%; /* 據上百分之50 */ left: 50%; /* 據下百分之50 */ margin-top: -200px; /* 在向上挪動本身高一半的位置 */ margin-left: -300px; /* 在向左挪動本身寬一半的位置 */ z-index: 1000; /* 要靠近你,比下面那層要靠近用戶 */ } </style> </head> <body> <div class="modal"></div> <div class="cover"></div> </body> </html>